Submission #204534

#TimeUsernameProblemLanguageResultExecution timeMemory
204534WLZDivide and conquer (IZhO14_divide)C++14
100 / 100
59 ms5996 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> x(n + 1), g(n + 1, 0), d(n + 1, 0); vector< pair<long long, int> > v; for (int i = 1; i <= n; i++) { cin >> x[i] >> g[i] >> d[i]; g[i] += g[i - 1]; d[i] += d[i - 1]; v.push_back({d[i] - x[i], i}); } sort(v.begin(), v.end()); vector<long long> a(n), mx(n); for (int i = 0; i < n; i++) { a[i] = v[i].first; } for (int i = n - 1; i >= 0; i--) { mx[i] = g[v[i].second]; if (i < n - 1) { mx[i] = max(mx[i], mx[i + 1]); } } long long ans = 0; for (int i = 1; i <= n; i++) { int j = lower_bound(a.begin(), a.end(), d[i - 1] - x[i]) - a.begin(); ans = max(ans, mx[j] - g[i - 1]); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...