# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37850 | 2017-12-28T10:26:23 Z | Just_Solve_The_Problem | Divide and conquer (IZhO14_divide) | C++11 | 3 ms | 5532 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; ll pg[N], pd[N]; int x[N], g[N], d[N], a[N]; int suf[N]; ll ans = 0; main () { int n; scanf ("%d", &n); for (int i = 1; i <= n; i++) { scanf ("%d %d %d", x + i, g + i, d + i); pd[i] = pd[i - 1] + d[i]; pg[i] = pg[i - 1] + g[i]; a[i] = pd[i] - x[i]; } suf[n + 1] = -inf; for (int i = n; i >= 1; i--) { suf[i] = max(suf[i + 1], a[i]); } for (int i = 1; i <= n; i++) { int l = i; int r = n; while (r - l > 1) { int mid = (l + r) >> 1; if (suf[mid] >= pd[i - 1] - x[i]) { l = mid; } else { r = mid; } } if (suf[r] >= pd[i - 1] - x[i]) { l = r; } ans = max(ans, pg[l] - pg[i - 1]); } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5532 KB | Output is correct |
2 | Correct | 0 ms | 5532 KB | Output is correct |
3 | Correct | 0 ms | 5532 KB | Output is correct |
4 | Correct | 0 ms | 5532 KB | Output is correct |
5 | Correct | 0 ms | 5532 KB | Output is correct |
6 | Correct | 0 ms | 5532 KB | Output is correct |
7 | Correct | 0 ms | 5532 KB | Output is correct |
8 | Correct | 0 ms | 5532 KB | Output is correct |
9 | Correct | 0 ms | 5532 KB | Output is correct |
10 | Correct | 0 ms | 5532 KB | Output is correct |
11 | Correct | 0 ms | 5532 KB | Output is correct |
12 | Correct | 0 ms | 5532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5532 KB | Output is correct |
2 | Correct | 0 ms | 5532 KB | Output is correct |
3 | Correct | 0 ms | 5532 KB | Output is correct |
4 | Correct | 0 ms | 5532 KB | Output is correct |
5 | Correct | 0 ms | 5532 KB | Output is correct |
6 | Incorrect | 0 ms | 5532 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5532 KB | Output is correct |
2 | Correct | 3 ms | 5532 KB | Output is correct |
3 | Incorrect | 3 ms | 5532 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |