fork download
  1. #include<iostream>
  2. #include<utility>
  3. #include<algorithm>
  4. #include<string>
  5. #include<math.h>
  6. #include<vector>
  7. #include<iterator>
  8. using namespace std;
  9. #define nitro ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
  10. #define ll long long int
  11. int main()
  12. {
  13. nitro;
  14. int t;
  15. cin>>t;
  16. while(t--)
  17. {
  18. ll n,i;
  19. cin>>n;
  20. vector<ll> a(n);
  21. for(auto &i: a)
  22. cin>>i;
  23. ll q,answer;
  24. cin>>q;
  25. while(q--)
  26. {
  27. ll x,y,z;
  28. cin>>x>>y;
  29. z=x+y;
  30. vector<ll> :: iterator lower;
  31. lower= lower_bound(a.begin(),a.end(),z);
  32. int k=lower-a.begin();
  33. if(z==a[k])
  34. answer=-1;
  35. else
  36. answer=k;
  37. cout<<answer<<endl;
  38. }
  39. cout << "Garbage Value of a[n] is : " << a[n] << endl;
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 4544KB
stdin
1
3
1 2 3
3
0 0
2 2
98593 0
stdout
0
3
-1
Garbage Value of a[n] is : 98593