#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, q;cin>>n>>q; int d[n+1], c[n+1], r[q], v[q];
for(int i=1; i<=n; i++){
cin>>d[i]>>c[i];
}
for(int i=0; i<q;i++){cin>>r[i]>>v[i];}
for(int i =0;i <q; i++){
int pab = r[i]; int paskd = d[r[i]];v[i] -= c[r[i]];
while(pab!= n+1 && v[i] >0){
if(paskd<d[pab]){
//cout<<"alip";
v[i] -= c[pab];
paskd = d[pab];
}
//cout<<"pask d " <<paskd<<" "<<pab<<" v[i] "<<v[i]<<endl;
if(v[i] >0){
pab++;
}
}
if(pab ==n+1){cout<<0<<"\n";}
else{cout<<pab<<"\n";}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1584 ms |
4896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Execution timed out |
1584 ms |
4896 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |