Submission #171395

#TimeUsernameProblemLanguageResultExecution timeMemory
171395NightmarDivide and conquer (IZhO14_divide)C++17
100 / 100
121 ms7944 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define read freopen("input.txt", "r", stdin) #define write freopen("output.txt", "w", stdout) #define files read; write using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = (int)2e3 + 228; const int N = (int)3e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; const ll LLINF = (ll)1e15 + 228; struct kek { ll x, g, d; }; kek a[N]; ll t[4 * N], add[4 * N], pref[N]; void push(int v, int tl, int tr) { if (tl != tr) { add[2 * v] += add[v]; add[2 * v + 1] += add[v]; } t[v] += add[v]; add[v] = 0; } void update(int v, int tl, int tr, int l, int r, ll x) { push(v, tl, tr); if (tl >= l && tr <= r) { add[v] = x; push(v, tl, tr); return; } if (tl > r || tr < l) return; int mid = (tl + tr) / 2; update(2 * v, tl, mid, l, r, x); update(2 * v + 1, mid + 1, tr, l, r, x); t[v] = max(t[2 * v], t[2 * v + 1]); } int get_r(int v, int tl, int tr) { push(v, tl, tr); if (tl == tr) return tl; int mid = (tl + tr) / 2; if (t[2 * v + 1] + add[2 * v + 1] >= 0) return get_r(2 * v + 1, mid + 1, tr); else return get_r(2 * v, tl, mid); } int main() { SWS; //files; int n; cin >> n; for (int i = 1; i <= n; i++) { int x, g, d; cin >> x >> g >> d; a[i] = {x, g, d}; pref[i] = pref[i - 1] + g; } ll ans = 0; for (int i = n; i > 0; i--) { if (i != n) update(1, 1, n, i + 1, n, a[i].x - a[i + 1].x); update(1, 1, n, i, n, a[i].d); int r = get_r(1, 1, n); ans = max(ans, pref[r] - pref[i - 1]); } cout << ans; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...