#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
int d[n], c[n];
for (int i = 0; i<n; i++)
{
cin>>d[i]>>c[i];
}
while (q--)
{
int start, litres;
cin>>start>>litres;
int current = d[start-1];
litres-=c[start-1];
if (litres<=0)
{
cout<<start<<endl;
continue;
}
bool b = false;
for (int i = start; i<n; i++)
{
if (d[i]>current)
{
current = d[i];
litres-=c[i];
if (litres<=0)
{
cout<<i+1<<endl;
b = true;
break;
}
}
}
if (!b)
{
cout<<0<<endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1545 ms |
3788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1545 ms |
3788 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |