이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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].second;
        else pre[i]=pre[i-1]+pr[i].second;
        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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |