#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
int const maxin = 1e5+6;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a,q;
bool flag = true ;
cin>>a>>q;
pair<ll , ll> arr[a];
arr[0].first = 0;
for(int i=1;i<a+1;i++)
{
cin>>arr[i].first>>arr[i].second;
if(arr[i-1].first >= arr[i].first)
flag = false ;
}
if(flag)
{
ll prf[a+1] = {0};
for(int i=1;i<a+1;i++)
{
prf[i] = prf[i-1] + arr[i].second;
}
while(q--)
{
ll x,y;
cin>>x>>y;
y+=prf[x-1];
if(y > prf[a])
cout<<0<<endl;
else
cout<<lower_bound(prf,prf+a+1,y)-prf<<endl;
}
}
else
{
while(q--)
{
ll x,y;
cin>>x>>y;
ll last = arr[x].first;
y-=arr[x].second;
if(y <= 0)
cout<<x<<endl;
else
{
for(int i=x+1;i<a+1;i++)
{
if(arr[i].first > last)
{
last = arr[i].first;
y-=arr[i].second;
}
if(y <= 0)
{
cout<<i<<endl;
break;
}
}
if(y > 0)
cout<<0<<endl;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
3268 KB |
Output is correct |
2 |
Correct |
79 ms |
3144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
85 ms |
3268 KB |
Output is correct |
9 |
Correct |
79 ms |
3144 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
1548 ms |
1548 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |