Submission #37400

# Submission time Handle Problem Language Result Execution time Memory
37400 2017-12-25T05:00:18 Z HardNut Divide and conquer (IZhO14_divide) C++14
0 / 100
0 ms 6704 KB
#include<iostream>
#include<cstdio>

using namespace std;

const int N = 1e5 + 5;

typedef long long ll;

ll ans, n, x[N], g[N], e[N];
ll t[N];
ll dpp[N], dp[N];

void build(int v, int L, int R) {
    if (L == R) {
        t[v] =  dpp[L - 1] - x[L];
        return;
    }
    int md = (L + R) >> 1;
    build(v * 2, L, md);
    build(v * 2 + 1, md + 1, R);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
}

ll get(int v, int L, int R, int l, int r) {
    if (L > r || l > R)
        return 1e9 + 5;
    if (l <= L && R <= r)
        return t[v];
    int md = (L + R) >> 1;
    return min(get(v * 2, L, md, l, r), get(v * 2 + 1, md + 1, R, l, r));
}

int main() {
    freopen("divide.in", "r", stdin);
    freopen("divide.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> e[i];
        dp[i] = dp[i - 1] + g[i];
        dpp[i] = dpp[i - 1] + e[i];
    }
    build(1, 1, n);
    for (int i = 1; i <= n; i++) {
        int l = 0, r = i;
        while (r - l > 1) {
            int md = (l + r) >> 1;
            if (get(1, 1, n, 1, md) <= dpp[i] - x[i]) {
                r = md;
            } else {
                l = md;
            }
        }
        ans = max(ans, dp[i] - dp[r - 1]);
    }
    cout << ans;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:35:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.in", "r", stdin);
                                     ^
divide.cpp:36:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.out", "w", stdout);
                                       ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 6704 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 6704 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 6704 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -