This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,q;
cin>>n>>q;
pair<long long,long long> niza[n];
for(long long i=0; i<n; i++)cin>>niza[i].first>>niza[i].second;
for(long long i=0; i<q; i++)
{
long long r,v;
cin>>r>>v;
r--;
v-=niza[r].second;
if(v<=0)
{
cout<<r+1<<endl;
continue;
}
long long last=niza[r].first;
r++;
while(v>0)
{
if(niza[r].first>last)
{
v-=niza[r].second;
last=niza[r].first;
if(v<=0)break;
}
r++;
if(r==n)break;
}
if(r>=n)
{
cout<<0<<endl;
}
else
{
cout<<r+1<<endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |