#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("Ofast")
int32_t main () {
int n, q;
cin >> n >> q;
vector<int> d;
vector<int> c;
for(int i = 0;i<n;i++) {
int a, b;
cin >> a >> b;
d.push_back(a);
c.push_back(b);
}
while(q--) {
int i, v;
cin >> i >> v;
i--;
int prev = i;
while(v > 0 and i < n) {
if(prev == i)v-=c[i];
else if(d[i] > d[prev]) {
v-=c[i];
prev = i;
}
i++;
}
if(v > 0)cout<<0<<endl;
else cout<<i<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
5 ms |
332 KB |
Output is correct |
5 |
Correct |
7 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 |
1594 ms |
2072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
5 ms |
332 KB |
Output is correct |
5 |
Correct |
7 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 |
1594 ms |
2072 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |