Submission #576422

#TimeUsernameProblemLanguageResultExecution timeMemory
576422emad234Fountain (eJOI20_fountain)C++17
30 / 100
66 ms2116 KiB
#include <bits/stdc++.h> #define all(v) ((v).begin(),(v).end()) typedef long long ll; using namespace std; const int mod = 1e9 + 7; const int mxN = 2e6 + 1; pair<int,int> a[mxN]; int prfx[mxN]; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,q; cin >>n>>q; for(int i = 1;i <= n;i++){ cin >>a[i].first>>a[i].second; } a[n + 1].first = INT_MAX;a[n + 1].second = INT_MAX; for(int i = 1;i <= n + 1;i++){ prfx[i] = prfx[i - 1] + a[i].second; } while(q--){ int r,v; cin >>r>>v; // if(n <= 1000 && q <= 2000){ // int prev = a[r].first - 1; // for(int i = r;i <= n + 1;i++){ // if(a[i].first > prev){ // prev = a[i].first; // v -= a[i].second; // } // if(v <= 0){ // if(i == n + 1) // cout<<0<<'\n'; // else // cout <<i<<'\n'; // break; // } // } // }else{ int x = lower_bound(prfx,prfx + n + 1,v + prfx[r - 1]) - prfx; if(x == n + 1) cout<<0<<'\n'; else cout<<x<<'\n'; } } // nice
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...