#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);
c.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 = 0;
while (v > c[it] || d[it] <= baa) {
if (d[it] > baa) {
baa = d[it];
v -= c[it];
}
it++;
if (it == n + 1) {
it = 0;
break;
}
}
//int it = lower_bo(1, n, v + pre[r - 1]);
cout << it << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
332 KB |
Output is correct |
7 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1593 ms |
1680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
332 KB |
Output is correct |
7 |
Correct |
6 ms |
332 KB |
Output is correct |
8 |
Execution timed out |
1593 ms |
1680 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |