Submission #576515

#TimeUsernameProblemLanguageResultExecution timeMemory
576515ammar124Fountain (eJOI20_fountain)C++14
60 / 100
1548 ms3268 KiB
#include <bits/stdc++.h> #define endl '\n' #define ll long long using namespace std; int const maxin = 1e5+6; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int a,q; bool flag = true ; cin>>a>>q; pair<ll , ll> arr[a]; arr[0].first = 0; for(int i=1;i<a+1;i++) { cin>>arr[i].first>>arr[i].second; if(arr[i-1].first >= arr[i].first) flag = false ; } if(flag) { ll prf[a+1] = {0}; for(int i=1;i<a+1;i++) { prf[i] = prf[i-1] + arr[i].second; } while(q--) { ll x,y; cin>>x>>y; y+=prf[x-1]; if(y > prf[a]) cout<<0<<endl; else cout<<lower_bound(prf,prf+a+1,y)-prf<<endl; } } else { while(q--) { ll x,y; cin>>x>>y; ll last = arr[x].first; y-=arr[x].second; if(y <= 0) cout<<x<<endl; else { for(int i=x+1;i<a+1;i++) { if(arr[i].first > last) { last = arr[i].first; y-=arr[i].second; } if(y <= 0) { cout<<i<<endl; break; } } if(y > 0) cout<<0<<endl; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...