답안 #344679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344679 2021-01-06T07:39:26 Z _zheksenov 금 캐기 (IZhO14_divide) C++14
100 / 100
59 ms 5100 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef long long ll;

const int N = 1e6 + 7;

int t[N << 2], g[N], x[N], d[N];

void modify(int pos, int val, int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = val;
        return;
    }  
    int mid = (tl + tr) >> 1;
    if (pos <= mid) {
        modify(pos, val, v << 1, tl, mid);
    } else {
        modify(pos, val, v << 1 | 1, mid + 1, tr);
    }
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}

int kth(int v, int tl, int tr, int k) {
    if (tl == tr)
        return tl;
    int mid = (tl + tr) >> 1;
    if (k <= t[v << 1 | 1]) {
        return kth(v << 1 | 1, mid + 1, tr, k);
    } else { 
        return kth(v << 1, tl, mid, k);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int b, c;
        cin >> x[i] >> b >> c;
        d[i] = d[i - 1] + c;
        g[i] = g[i - 1] + b;
        modify(i, d[i] - x[i], 1, 1, n);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int get = kth(1, 1, n, d[i - 1] - x[i]);
        ans = max(ans, g[get] - g[i - 1]);
    }
    cout << ans << "\n";   
    return 0;
}       
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 5 ms 1004 KB Output is correct
27 Correct 5 ms 1004 KB Output is correct
28 Correct 25 ms 3052 KB Output is correct
29 Correct 31 ms 2796 KB Output is correct
30 Correct 54 ms 4972 KB Output is correct
31 Correct 53 ms 5100 KB Output is correct
32 Correct 49 ms 4972 KB Output is correct
33 Correct 59 ms 4972 KB Output is correct
34 Correct 48 ms 4972 KB Output is correct
35 Correct 53 ms 4972 KB Output is correct
36 Correct 53 ms 4972 KB Output is correct