Submission #576443

#TimeUsernameProblemLanguageResultExecution timeMemory
576443vqpahmadFountain (eJOI20_fountain)C++14
0 / 100
55 ms2372 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; int cnt = 0; v-=a[d].second; if (v>=0) cnt++; d++; while(d<n&&v>0){ if (a[d].first > mx){ v-=a[d].second; if (v>=0) cnt++; } 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].first; } while (q--){ int d,v; cin >> d >> v; ll num = pref[d]; int up = upper_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...