Submission #1010886

# Submission time Handle Problem Language Result Execution time Memory
1010886 2024-06-29T13:21:15 Z phoenix Divide and conquer (IZhO14_divide) C++17
100 / 100
38 ms 5980 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n;
int x[N], g[N], d[N];

long long sum[N];
long long val[N];

long long recur(int l, int r) {
    if (l == r) {
        return g[l];
    }
    int mid = (l + r) / 2;
    long long s;
    s = 0; 
    sum[l] = sum[r] = 0;
    for (int i = mid; i >= l; i--) {
        sum[i] = (sum[l] += g[i]);
        s += d[i];
        val[i] = s + x[i];
    }
    s = 0;
    for (int i = mid + 1; i <= r; i++) {
        sum[i] = (sum[r] += g[i]);
        s += d[i];
        val[i] = x[i] - s;
    }
    for (int i = r; i > mid + 1; i--) 
        val[i - 1] = min(val[i - 1], val[i]);
    
    long long res = 0;
    for (int i = mid; i >= l; i--) {
        int lb = mid, rb = r + 1;
        while (rb - lb > 1) {
            int m = (lb + rb) / 2;
            if (val[m] <= val[i]) lb = m;
            else rb = m;
        }
        if (lb > mid) res = max(res, sum[i] + sum[lb]);
    }
    res = max(res, recur(l, mid));
    res = max(res, recur(mid + 1, r));
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> g[i] >> d[i];
    }
    cout << recur(0, n - 1);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2560 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2560 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2560 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2560 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 3 ms 2748 KB Output is correct
27 Correct 3 ms 2652 KB Output is correct
28 Correct 16 ms 3904 KB Output is correct
29 Correct 18 ms 4188 KB Output is correct
30 Correct 38 ms 5980 KB Output is correct
31 Correct 33 ms 4700 KB Output is correct
32 Correct 37 ms 4952 KB Output is correct
33 Correct 33 ms 4696 KB Output is correct
34 Correct 31 ms 4700 KB Output is correct
35 Correct 32 ms 5212 KB Output is correct
36 Correct 32 ms 5508 KB Output is correct