Submission #448056

#TimeUsernameProblemLanguageResultExecution timeMemory
448056fuad27Fountain (eJOI20_fountain)C++14
60 / 100
1579 ms6288 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #pragma GCC optimize("Ofast") int32_t main () { int n, q; cin >> n >> q; vector<int> d(n, 0); vector<int> c(n, 0); vector<int> prefix(n+1, 0); bool increasing = true; for(int i=0;i<n;i++) { int a, b; cin >> a >> b; d[i] = a; c[i] = b; prefix[i+1] = prefix[i] + c[i]; if(i > 0 and d[i] <= d[i-1])increasing = false; } while(q--) { int i, v; cin >> i >> v; i--; if(increasing) { int l = i, u = n - 1, ans = 0; while(l <= u) { int mid = l+(u-l)/2; if(prefix[mid+1] - prefix[i] >= v) { ans = mid; u = mid - 1; } else { l = mid + 1; } } if(prefix[n] < v) { cout<<0<<endl; } else cout<<ans+1<<endl; } else { int prev = i; while(v > 0 and i < n) { if(prev == i)v-=c[i]; else if(d[i] > d[prev]) { v-=c[i]; prev = i; } i++; } if(v > 0)cout<<0<<endl; else cout<<i<<endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...