Submission #576490

#TimeUsernameProblemLanguageResultExecution timeMemory
576490vqpahmadFountain (eJOI20_fountain)C++14
60 / 100
72 ms2468 KiB
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define all(a) a.begin(),a.end() #define mod (ll)(10000007) using namespace std; const int mx = 1e6 + 15; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,q; cin >> n >> q; vector<pair<int,int>> a(n);//fist diamter , second is water for (int i=0;i<n;i++){ cin >> a[i].first >> a[i].second; } if (n<=1000&&q<=2000){ while (q--){ int d,v; cin >> d >> v; d--; int mx=a[d].first; v-=a[d].second; d++; while(d<n&&v>0){ if (a[d].first > mx){ mx = a[d].first; v-=a[d].second; } d++; } d<n?cout << d << endl:cout << 0 << endl; } } else { vector<ll> pref(n+1); for (int i=1;i<=n;i++){ pref[i] = pref[i-1]+a[i-1].second; } while (q--){ int d,v; cin >> d >> v; ll num = pref[d-1]; int up = lower_bound(all(pref),num+v)-pref.begin(); up <= n ? cout << up <<endl : cout << 0 << endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...