#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n,q;
cin>>n>>q;
int koliko[n+1];
int staje[n+1];
for(int i=1;i<=n;i++)cin>>koliko[i]>>staje[i];
while(q--){
int r,k;
cin>>r>>k;
vector<int>R;
int z=r;
R.push_back(r);
for(int i=z;i<n;i=z){
//cout<<i<<" ";
int ok=0;
for(int j=i+1;j<=n;j++){
if(koliko[i]<koliko[j]){
ok=1;
z=j;
R.push_back(j);
break;
}
}
if(!ok)break;
}
int ans=0;
for(auto it:R){
k-=staje[it];
if(k<=0){
ans=it;
break;
}
}
cout<<ans;
cout<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
464 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1558 ms |
5360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
464 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
1558 ms |
5360 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |