Submission #255260

#TimeUsernameProblemLanguageResultExecution timeMemory
255260tunaDivide and conquer (IZhO14_divide)C++11
100 / 100
852 ms100784 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 1e6 + 5, M = 2e14; int n; ll x[N], g[N], d[N]; map<ll, ll> tree; void upd(ll k, ll x) { while (k < M) { if (tree.find(k) == tree.end()) { tree[k] = x; } else { tree[k] = min(tree[k], x); } k += k & -k; } } ll que(ll k) { ll ans = LLONG_MAX; while (k) { if (tree.find(k) != tree.end()) { ans = min(ans, tree[k]); } k -= k & -k; } return ans; } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> g[i] >> d[i]; d[i] += d[i - 1]; g[i] += g[i - 1]; } ll ans = 0; for (int i = 1; i <= n; i++) { upd(d[i - 1] - x[i] + M / 2, g[i - 1]); ans = max(ans, g[i] - que(d[i] - x[i] + M / 2)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...