#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q;
cin>>n>>q;
int d[n+1],c[n+1];
for(int i = 1;i <= n;i++){
cin>>d[i]>>c[i];
}
while(q--){
int r,v;
cin>>r>>v;
int cur = r;
v -= c[cur];
for(int i = cur + 1;i <= n;i++){
if(v <= 0){
break;
}
if(d[cur] < d[i]){
cur = i;
v -= c[i];
}
}
if(v > 0){
cout<<0<<endl;
}
else{
cout<<cur<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1517 ms |
3552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1517 ms |
3552 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |