Submission #916649

# Submission time Handle Problem Language Result Execution time Memory
916649 2024-01-26T08:32:24 Z atom Divide and conquer (IZhO14_divide) C++17
0 / 100
1 ms 348 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

const int N = 5e3 + 5;
int n;
int x[N], g[N], e[N];
ll dp[N], fe[N], fg[N];

ll cal(int l, int r, int t) {
    if (l > r) return 0LL;
    return (t? fg[r] - fg[l - 1] : fe[r] - fe[l - 1]);
}
void solve(int l, int r, int opt_l, int opt_r) {
    if (l > r) return;

    // debug(l, r, opt_l, opt_r);
    int m = (l + r) / 2;
    int split = -1;
    for (int i = opt_l; i <= min(m, opt_r); ++i) {
        ll req = x[m] - x[i];
        ll have = cal(i, m, 0);
        ll opt = dp[i] + 1LL * cal(i + 1, m, 1);
        if (have >= req && opt > dp[m]) {
            dp[m] = opt;
            split = i;
        }
    }

    solve(l, m - 1, opt_l, split);
    solve(m + 1, r, split, opt_r);
}
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
        
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> x[i] >> g[i] >> e[i];
    for (int i = 1; i <= n; ++i) {
        fg[i] = fg[i - 1] + g[i];
        fe[i] = fe[i - 1] + e[i];
    }

    for (int i = 1; i <= n; ++i) dp[i] = g[i];
    solve(1, n, 1, n);
    // for (int i = 1; i <= n; ++i) {
    //     debug(i, dp[i]);
    // }
    cout << *max_element(dp + 1, dp + 1 + n) << "\n";
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -