Submission #488700

#TimeUsernameProblemLanguageResultExecution timeMemory
488700SirCovidThe19thDivide and conquer (IZhO14_divide)C++17
100 / 100
116 ms7192 KiB
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 5, msz = (1 << 17); int n, X[mx]; long long G[mx], E[mx], seg[msz * 2], ans; void upd(int i, long long v){ seg[i += msz] = v; for (i /= 2; i; i /= 2) seg[i] = min(seg[i * 2], seg[i * 2 + 1]); } int qry(long long v){ int i = 1; while (i < msz) i = (seg[i * 2] <= v) ? i * 2 : i * 2 + 1; return i - msz; } int main(){ cin >> n; for (int i = 1; i <= n; i++){ cin >> X[i] >> G[i] >> E[i]; G[i] += G[i - 1]; E[i] += E[i - 1]; } memset(seg, 0x3f, sizeof(seg)); for (int i = 1; i <= n; i++){ upd(i, E[i - 1] - X[i]); int pos = qry(E[i] - X[i]); ans = max(ans, G[i] - G[pos - 1]); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...