| 15 | using namespace std; |
| 16 | |
| 17 | signed main() |
| 18 | { |
| 19 | int t; |
| 20 | cin >> t; |
| 21 | while (t--) |
| 22 | { |
| 23 | ll n, q, i, j; |
| 24 | cin >> n; |
| 25 | vector<ll> a(n); |
| 26 | //Taking input of array a[] |
| 27 | for (i = 0; i < n; i++) |
| 28 | cin >> a[i]; |
| 29 | cin >> q; |
| 30 | //Processing the queries |
| 31 | while (q--) |
| 32 | { |
| 33 | ll x, y; |
| 34 | cin >> x >> y; |
| 35 | //Adding the points as the equation is x+y |
| 36 | x += y; |
| 37 | //Applying the binary search function in array a[] |
| 38 | auto it = upper_bound(a.begin(), a.end(), x); |
| 39 | //If the point is below every given line, answer is 0 |
| 40 | if (it == a.begin()) |
| 41 | cout << "0" |
| 42 | << "\n"; |
| 43 | else |
| 44 | { |
| 45 | it--; |
| 46 | //If the point lies on a line we output the answer as -1 |
| 47 | if (*it == x) |
| 48 | cout << "-1" |
| 49 | << "\n"; |
| 50 | else |
| 51 | { |
| 52 | //The answer is the index we found in the array |
| 53 | ll ans = (it - a.begin()) + 1; |
| 54 | cout << ans << "\n"; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
nothing calls this directly
no outgoing calls
no test coverage detected