#include <vector>
#include <algorithm>
using namespace std;
#include <iostream>
vector<int> pre;
int n;
/*int lower_bo(int l, int r, int val) {
int mid = (l + r) / 2;
if (pre[mid] < val && (mid == n || pre[mid+1] >= val) ) {
return mid+1;
}
if (pre[mid] < val) {
return lower_bo(mid + 1, r, val);
}
if (pre[mid] > val) {
return lower_bo(l, mid - 1, val);
}
}*/
int main()
{
int q;
cin >> n >> q;
vector<int> d;
vector<int> c;
pre.push_back(0);
d.push_back(0);
for (int i = 1; i < n+1; i++) {
int x, y;
cin >> x >> y;
d.push_back(x);
pre.push_back(y+pre[i-1]);
c.push_back(y);
}
for (int i = 0; i < q; i++) {
int r, v;
cin >> r >> v;
int it = r;
int baa = d[r];
while (v > c[it]) {
if (it == n+1) {
it = 0;
break;
}
if (d[it] > baa) {
baa = d[it];
v -= c[it];
}
it++;
}
//int it = lower_bo(1, n, v + pre[r - 1]);
cout << it << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1579 ms |
1972 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |