#include <bits/stdc++.h>
using namespace std;
#define debug(var) cerr<<"#"<<#var<<"="<<var<<endl;
struct Recip{
int diametre;
int capacite;
void read(){
cin>>diametre;
cin>>capacite;
};
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q;cin>>n>>q;
vector<Recip> recipient(n);
for(int i = 0 ; i <n;i++)recipient[i].read();
for(int i=0;i<q;i++){
int id;cin>>id;id--;
int volume;cin>>volume;
int act = id;
volume-=min(volume,recipient[id].capacite);
for(int j=id+1;j<n && volume;j++){
if(recipient[act].diametre<recipient[j].diametre){
volume-=min(volume,recipient[j].capacite);
act=j;
}
}
if(volume){
act=-1;
}
cout<<act+1<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1573 ms |
2996 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
1573 ms |
2996 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |