제출 #440690

#제출 시각아이디문제언어결과실행 시간메모리
440690MrDebooFountain (eJOI20_fountain)C++17
0 / 100
75 ms3140 KiB
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define endl '\n'
using namespace std;
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    pair<int,int>pr[n];
    int pre[n];
    bool bl=true;
    for(int i=0;i<n;i++){
        cin>>pr[i].first>>pr[i].second;
        if(i==0)pre[i]=pr[i].first;
        else pre[i]=pre[i-1]+pr[i].first;
        if(i>0&&pr[i].first<=pr[i-1].first)bl=false;
    }
    while(q--){
        int r,v;
        cin>>r>>v;
        r--;
        if(bl){
            int k=lower_bound(pre,pre+n,v+(r==0?0:pre[r-1]))-pre;
            cout<<(k+1)%(n+1)<<endl;
        }
        else{
            for(int i=r;i<n;i++){
                if(pr[i].first>pr[r].first||i==r){v-=pr[i].second;r=i;}
                if(v<=0){cout<<i+1<<endl;break;}
                if(i==n-1)cout<<0<<endl;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...