답안 #655520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655520 2022-11-04T16:16:16 Z stevancv 금 캐기 (IZhO14_divide) C++14
100 / 100
34 ms 6240 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<ll> x(n + 1), g(n + 1), e(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> e[i];
        g[i] += g[i - 1];
        e[i] += e[i - 1];
    }
    vector<ll> pref(n + 1);
    for (int i = 1; i <= n; i++) pref[i] = max(pref[i - 1], x[i] - e[i - 1]);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int l = 1; int r = i; int id = -1;
        while (l <= r) {
            int mid = l + r >> 1;
            if (pref[mid] >= x[i] - e[i]) {
                r = mid - 1;
                id = mid;
            }
            else l = mid + 1;
        }
        if (id == -1) continue;
        smax(ans, g[i] - g[id - 1]);
    }
    cout << ans << en;
    return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:28:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |             int mid = l + r >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 544 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 544 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 668 KB Output is correct
27 Correct 3 ms 720 KB Output is correct
28 Correct 14 ms 2764 KB Output is correct
29 Correct 19 ms 3276 KB Output is correct
30 Correct 34 ms 6240 KB Output is correct
31 Correct 26 ms 5092 KB Output is correct
32 Correct 27 ms 5224 KB Output is correct
33 Correct 25 ms 4972 KB Output is correct
34 Correct 27 ms 4972 KB Output is correct
35 Correct 27 ms 5584 KB Output is correct
36 Correct 28 ms 5720 KB Output is correct