답안 #951331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951331 2024-03-21T15:45:38 Z LOLOLO 금 캐기 (IZhO14_divide) C++17
100 / 100
97 ms 28404 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 2e5 + 100;
ll seg[N * 4], dp[N];
int n;

void point(int id, int l, int r, int p, ll v) {
    if (l > p || r < p)
        return;

    seg[id] = min(seg[id], v);
    if (l == r)
        return;

    int m = (l + r) / 2;
    point(id * 2, l, m, p, v);
    point(id * 2 + 1, m + 1, r, p, v);
}

ll get(int id, int l, int r, int u, int v) {
    if (l > v || r < u)
        return 1e18;

    if (l >= u && r <= v)
        return seg[id];

    int m = (l + r) / 2;
    return min(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}

ll x[N], g[N], d[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;

    fill(seg, seg + n * 8 + 10, 1e18);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> d[i];
        g[i] += g[i - 1];
        d[i] += d[i - 1];
    }

    map <ll, int> mp;
    int timer = 1;
    for (int i = 1; i <= n; i++) {
        mp[x[i] - d[i - 1]];
        mp[x[i] - d[i]];
    }

    for (auto &x : mp) {
        x.s = timer;
        timer++;
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int p = mp[x[i] - d[i]];
        point(1, 1, n * 2, mp[x[i] - d[i - 1]], g[i - 1]);
        ans = max({ans, g[i] - get(1, 1, n * 2, p, n * 2)});
    }

    cout << ans << '\n';
    return 0;
}

/*
en[i] = g[1] + g[2] +..+ g[i];
s[i] =  d[1] + d[2] +..+ d[i];
dp[i] = tổng lớn nhất.
dp[i] = max(dp[i - 1], dp[j - 1] + en[i] - en[j - 1]); 
(x[i] - x[j] <= s[i] - s[j - 1])
<=> x[i] - s[i] <= x[j] - s[j - 1]
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6612 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6612 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 5 ms 9308 KB Output is correct
24 Correct 5 ms 9308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6612 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 5 ms 9308 KB Output is correct
24 Correct 5 ms 9308 KB Output is correct
25 Correct 4 ms 9304 KB Output is correct
26 Correct 8 ms 10076 KB Output is correct
27 Correct 8 ms 10072 KB Output is correct
28 Correct 37 ms 18008 KB Output is correct
29 Correct 39 ms 18284 KB Output is correct
30 Correct 97 ms 28404 KB Output is correct
31 Correct 90 ms 27044 KB Output is correct
32 Correct 89 ms 27308 KB Output is correct
33 Correct 74 ms 26876 KB Output is correct
34 Correct 93 ms 26692 KB Output is correct
35 Correct 89 ms 27472 KB Output is correct
36 Correct 81 ms 27808 KB Output is correct