답안 #342666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342666 2021-01-02T15:46:04 Z apostoldaniel854 금 캐기 (IZhO14_divide) C++14
100 / 100
38 ms 6000 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int MAX_N = 1e5;

ll mn[1 + MAX_N];
int x[1 + MAX_N];
ll d[1 + MAX_N];
ll g[1 + MAX_N];

inline int get (int sz, ll bound) {
    int lb = 1, rb = sz, best;
    while (lb <= rb) {
        int mid = (lb + rb) / 2;
        if (mn[mid] <= bound)
            best = mid, rb = mid - 1;
        else
            lb = mid + 1;
    }
    return best;
}

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    int n;
    cin >> n;
    ll ans = 0;
    mn[0] = (1ll << 60);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> d[i];
        d[i] += d[i - 1];
        g[i] += g[i - 1];
        mn[i] = min (mn[i - 1], d[i - 1] - x[i]);
        ans = max (ans, g[i] - g[get (i, d[i] - x[i]) - 1]);
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:41:55: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         ans = max (ans, g[i] - g[get (i, d[i] - x[i]) - 1]);
      |                                  ~~~~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 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 364 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 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 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 364 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 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 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 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 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 364 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 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 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 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 4 ms 876 KB Output is correct
28 Correct 16 ms 2796 KB Output is correct
29 Correct 19 ms 3072 KB Output is correct
30 Correct 38 ms 6000 KB Output is correct
31 Correct 33 ms 4844 KB Output is correct
32 Correct 31 ms 4844 KB Output is correct
33 Correct 30 ms 4716 KB Output is correct
34 Correct 31 ms 4716 KB Output is correct
35 Correct 34 ms 5228 KB Output is correct
36 Correct 35 ms 5356 KB Output is correct