Submission #396373

#TimeUsernameProblemLanguageResultExecution timeMemory
396373jeroenodbDivide and conquer (IZhO14_divide)C++14
0 / 100
1 ms292 KiB
#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1e5+1, oo = 1e9; struct el { ll pref, gold; bool operator>(const el& o) const { return pref < o.pref; } }; int main() { int n; cin >> n; ll sum = 0,pref=0; ll ans = 0; vector<el> st; st.reserve(n); for(int i=0;i<n;++i) { int x,g,d; cin >> x >> g >> d; ans = max((ll)g,ans); int l=0,r=st.size(); while(l<r) { int mid = (l+r)/2; if(st[mid].pref<=pref+d-x) { r = mid; } else { l = mid+1; } } if(l!=(int)st.size()) { ans = max(sum+g-st[l].gold, ans); } if(i==n-1) break; el nw = {pref-x,sum}; while(!st.empty() and st.back()>nw) { st.pop_back(); } st.push_back(nw); pref += d; sum+=g; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...