fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. cin>>n;
  7.  
  8. vector<int>a(n);
  9. vector<int>b(n);
  10.  
  11. for(int i = 0; i < n; i++) {
  12. cin>>a[i];
  13. }
  14.  
  15. for(int j = 0; j < n; j++) {
  16. cin>>b[j];
  17. }
  18.  
  19. sort(a.begin(), a.end());
  20. sort(b.begin(), b.end());
  21.  
  22. int i = 0, j = 1;
  23. int x = 0, y = n-1;
  24.  
  25. unordered_map<int,int>umap;
  26. while(i < n && j <= n && x < y) {
  27. int val1 = a[i] + b[y];
  28. int val2 = a[j] + b[x];
  29. umap[a[i] + b[y]]++;
  30. umap[a[j] + b[x]]++;
  31.  
  32. i+=2;
  33. j+=2;
  34. x++;
  35. y--;
  36.  
  37. if(umap[val1] >= 3 || umap[val2] >= 3) {
  38. cout<<"Yes"<<endl;
  39. return ;
  40. }
  41. }
  42.  
  43. cout<<"No"<<endl;
  44. }
  45.  
  46. int main() {
  47. int t;
  48. cin>>t;
  49.  
  50. while(t--) {
  51. solve();
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
4
1 2 1 2
1 2 1 2
6
1 2 3 3 2 1
1 1 1 1 1 1
3
1 1 1
1 1 1
6
1 52 52 3 1 3
59 4 3 59 3 4
4
100 1 100 1
2 2 2 2
stdout
No
No
No
No
No