#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,q,d,c,r,v;
vector<pair<int,int> > reservoir;
cin>>n>>q;
for(int i=0;i<n;i++){
cin>>d>>c;
reservoir.push_back(make_pair(d,c));
}
//works ^
while(q--){
cin>>r>>v;
for(int i=r-1;i<n;i=i){
if(reservoir[i].second>=v){
cout<<i+1<<"\n";
break;
}
else if(i+1==n){
cout<<0<<"\n";
break;
}
else{
for(int j=i+1;j<n;j++){
if(reservoir[i].first>=reservoir[j].first&&j!=n-1)
continue;
else if(reservoir[i].first>=reservoir[j].first&&j==n-1){
cout<<0<<"\n";
i=n;
break;
}
else{
//cout<<j<<" j\n";
v-=reservoir[i].second;
i=j;
//cout<<v<<" v\n";
//cout<<reservoir[i].second<<" reservoir[i].second\n";
break;
}
}
}
}
}
}
# |
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 |
204 KB |
Output is correct |
5 |
Correct |
9 ms |
204 KB |
Output is correct |
6 |
Correct |
9 ms |
308 KB |
Output is correct |
7 |
Correct |
6 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1582 ms |
1340 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 |
204 KB |
Output is correct |
5 |
Correct |
9 ms |
204 KB |
Output is correct |
6 |
Correct |
9 ms |
308 KB |
Output is correct |
7 |
Correct |
6 ms |
204 KB |
Output is correct |
8 |
Execution timed out |
1582 ms |
1340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |