Submission #576541

#TimeUsernameProblemLanguageResultExecution timeMemory
576541JassarFountain (eJOI20_fountain)C++14
30 / 100
255 ms3520 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll n,q; cin >> n >> q; vector<pair<ll , ll>> v; stack<ll> s; ll sum[n]; for (ll i=0; n>i; i++) { ll a,b; cin >> a >> b; v.push_back({a , b}); sum[i] = v[i].second; if (i > 0) sum[i] += sum[i-1]; } while (q--) { ll a,b; cin >> a >> b; a--; int g = b; if (a > 0) { g += sum[a-1]; } int l = 0 , mid = (n / 2) , r = n; while (l != r) { if (sum[mid] >= g) { r = mid; mid = (r + l) / 2; } else { l = mid + 1; mid = (l + r) / 2; } } if (r == n) { cout << 0 << endl; } else { cout << l + 1 << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...