fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define vec vector<ll>
  4. #define f(var,a,b) for(ll var = a ; var < b ; var++ )
  5. #define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
  6. using namespace std;
  7.  
  8. void att1( vec &v , ll x ) {
  9. ll n = v.size();
  10.  
  11. sort( v.begin() , v.end() ); // sorting the given array
  12.  
  13. // Applying 2 pointer
  14. ll left = 0, right = n-1;
  15. bool isAC = false;
  16.  
  17. while( left < right ) {
  18. if( v[left] + v[right] == x ) {
  19. isAC = true;
  20. break;
  21. }
  22. else if( v[left] + v[right] > x ) {
  23. right--;
  24. }
  25. else if( v[left] + v[right] < x ) {
  26. left++;
  27. }
  28. }
  29. if( isAC ) cout << "Accepted\n";
  30. else cout << "Rejected\n";
  31. }
  32.  
  33. int main(void){
  34.  
  35. fasthoja;
  36. ll t; cin>>t;
  37.  
  38. while(t--){
  39.  
  40. ll n; cin >> n;
  41. ll x = 2000;
  42. vec v(n); f(i,0,n) cin >> v[i];
  43. att1( v , x);
  44.  
  45. }//end of test case loop
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 4180KB
stdin
1
5
10 2 1000 50 1000
stdout
Accepted