Submission #632213

#TimeUsernameProblemLanguageResultExecution timeMemory
632213Jovan26Fountain (eJOI20_fountain)C++14
0 / 100
287 ms2120 KiB
#include<iostream> using namespace std; int d[100005]; int c[100005]; int ci[100005]; bool check(int r,int v,int x){ if(ci[x]-ci[r]<v) return true; return false; } int main(){ int n,q; cin>>n>>q; for(int i=1;i<n+1;i++) cin>>d[i]>>c[i]; ci[1] = 0; for(int i=2;i<=n;i++){ ci[i] = c[i-1]+ci[i-1]; } ci[0] = ci[n-1]+c[n]; for(int e = 0;e<q;e++){ int r,v; cin>>r>>v; if(ci[0]-ci[r]<v) cout<<0<<endl; else{ int l = r; int r1 = n; int cr = 0 ; while(r1>=l){ int mid = (r1+l)/2; if((r1+l)%2==1) mid++; if(check(r,v,mid)){ l = mid+1; cr = mid; } else{ r1 = mid-1; } } cout<<cr<<endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...