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>
#define all(v) ((v).begin(),(v).end())
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
pair<int,int> a[mxN];
int prfx[mxN];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,q;
cin >>n>>q;
for(int i = 1;i <= n;i++){
cin >>a[i].first>>a[i].second;
}
a[n + 1].first = INT_MAX;a[n + 1].second = INT_MAX;
for(int i = 1;i <= n + 1;i++){
prfx[i] = prfx[i - 1] + a[i].first;
}
while(q--){
int r,v;
cin >>r>>v;
if(n <= 1000 && q <= 2000){
int prev = a[r].first - 1;
for(int i = r;i <= n + 1;i++){
if(a[i].first > prev){
prev = a[i].first;
v -= a[i].second;
}
if(v <= 0){
if(i == n + 1)
cout<<0<<'\n';
else
cout <<i<<'\n';
break;
}
}
}else{
int x = lower_bound(prfx,prfx + n + 1,v + prfx[r - 1]) - prfx;
if(x == n + 1)
cout<<0<<'\n';
else
cout<<x<<'\n';
}
}
}
// nice
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |