Submission #632215

#TimeUsernameProblemLanguageResultExecution timeMemory
632215Jovan26Fountain (eJOI20_fountain)C++14
30 / 100
333 ms2020 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]; if(n<1005){ int p; for(int i=0;i<q;i++){ int r,v; cin>>r>>v; p=0; for(int j=r;j<=n;j++){ if(d[j]>p){ v-=c[j]; p=d[j]; } if(v<=0) { cout<<j<<endl; break; } if(j==n){ cout<<0<<endl; break; } } } return 0; } 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...