제출 #1128233

#제출 시각아이디문제언어결과실행 시간메모리
1128233ChocoFountain (eJOI20_fountain)C++20
0 / 100
1595 ms2096 KiB
#include<bits/stdc++.h> using namespace std; #define Study ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define ull unsigned long long #define pb push_back #define ff first #define ss second #define ins insert #define all(x) x.begin(),x.end() #define fori(x,y,z) for(ll x=y;x<=z;x++) const ll INF=1e9; const ll sz=2e5+10; const ll mod=1e9+7; void work(){ ll n,q; cin>>n>>q; vector<pair<ll,ll>>v(n+1); v[0].ss=-1;v[0].ff=-1; bool yes=0; fori(i,1,n){ ll d,x; cin>>d>>x; v[i].ff=d; v[i].ss=x; if(v[i].ff<v[i-1].ff){ yes=1; } } if(!yes){ while(q--){ ll d,l; cin>>d>>l; ll sum=v[d].ss; ll maxr=v[d].ff; d++; while(d<=n and sum<l){ if(v[d].ff>maxr){ sum+=v[d].ss; maxr=v[d].ff; } d++; } if(sum>=l) d--; //cout<<d<<' '<<sum<<endl; if(sum<l and d>=n) cout<<0<<endl; else cout<<d<<endl; } } else{ vector<ll>pref(n+10,0); fori(i,1,n){ pref[i]=pref[i-1]+v[i].ss; } while(q--){ ll d,x; cin>>d>>x; ll l=d; ll r=n; while(l<=r){ ll mid=(l+r+1)/2; if(pref[mid]-pref[d-1]<=x) l=mid; else r=mid+1; } if(pref[l]-pref[d-1]>x){ cout<<0<<endl; } else{ cout<<l<<endl; } } } } int main(){ Study; ll t=1; //cin>>t; while(t--){ work(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...