#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin>>n>>q;
long long int d[n], c[n];
for(int i=0; i<n; i++)
{
cin>>d[i]>>c[i];
}
while(q--)
{
long long int nivo, voda;
cin>>nivo>>voda;
long long int curr=nivo, prev=d[nivo-1];
voda-=c[nivo-1];
bool kiki=0;
for(int i=nivo; i<n; i++)
{
if(d[i]>prev && voda>0)
{
prev=d[i];
voda-=c[i];
curr=i+1;
}
if(voda<=0)
{
kiki=1;
}
}
if(kiki)
cout<<curr<<"\n";
else
cout<<0<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1567 ms |
3088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1567 ms |
3088 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |