# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257494 | 2020-08-04T10:58:00 Z | karma | Feast (NOI19_feast) | C++14 | 198 ms | 17984 KB |
#include <bits/stdc++.h> #define pb emplace_back #define ll long long #define fi first #define se second #define mp make_pair //#define int int64_t using namespace std; const int N = int(6e5) + 7; typedef pair<ll, int> pii; pii f[N][2]; int n, k, a[N]; /// 0 - ok /// 1 - opening pii operator - (const pii& a, const ll& x) { return pii(a.fi - x, a.se + 1); } pii operator + (const pii& a, const ll& x) { return pii(a.fi + x, a.se); } pii max(const pii& x, const pii& y) { if(x.fi == y.fi) return x.se < y.se? x: y; return x.fi > y.fi? x: y; } pii check(ll mid) { for(int i = 1; i <= n; ++i) { f[i][1] = max(f[i - 1][1], f[i - 1][0]) + a[i]; f[i][0] = max(f[i - 1][1] - mid, f[i - 1][0]); } return max(f[n][0], f[n][1] - mid); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define Task "test" if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n >> k; for(int i = 1; i <= n; ++i) cin >> a[i]; ll low = 0, mid, high = 1ll * n * (int)1e9; n += k; while(low <= high) { mid = (low + high) >> 1; if(check(mid).se > k) low = mid + 1; else high = mid - 1; } cout << check(low).fi + 1ll * low * k; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 105 ms | 11256 KB | Output is correct |
2 | Correct | 144 ms | 15608 KB | Output is correct |
3 | Correct | 128 ms | 12284 KB | Output is correct |
4 | Correct | 116 ms | 12152 KB | Output is correct |
5 | Correct | 115 ms | 11668 KB | Output is correct |
6 | Correct | 124 ms | 11896 KB | Output is correct |
7 | Correct | 111 ms | 11896 KB | Output is correct |
8 | Correct | 102 ms | 10744 KB | Output is correct |
9 | Correct | 113 ms | 10688 KB | Output is correct |
10 | Correct | 103 ms | 10824 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 10616 KB | Output is correct |
2 | Correct | 86 ms | 10940 KB | Output is correct |
3 | Correct | 83 ms | 10624 KB | Output is correct |
4 | Correct | 118 ms | 15040 KB | Output is correct |
5 | Correct | 101 ms | 10616 KB | Output is correct |
6 | Correct | 83 ms | 10616 KB | Output is correct |
7 | Correct | 156 ms | 17400 KB | Output is correct |
8 | Correct | 110 ms | 11000 KB | Output is correct |
9 | Correct | 115 ms | 10744 KB | Output is correct |
10 | Correct | 109 ms | 12792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 10744 KB | Output is correct |
2 | Correct | 134 ms | 10616 KB | Output is correct |
3 | Correct | 125 ms | 10872 KB | Output is correct |
4 | Correct | 128 ms | 10616 KB | Output is correct |
5 | Correct | 129 ms | 10876 KB | Output is correct |
6 | Correct | 137 ms | 10888 KB | Output is correct |
7 | Correct | 141 ms | 10876 KB | Output is correct |
8 | Correct | 126 ms | 10748 KB | Output is correct |
9 | Correct | 131 ms | 10872 KB | Output is correct |
10 | Correct | 141 ms | 11000 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 432 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 384 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 384 KB | Output is correct |
27 | Correct | 1 ms | 512 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 105 ms | 11256 KB | Output is correct |
2 | Correct | 144 ms | 15608 KB | Output is correct |
3 | Correct | 128 ms | 12284 KB | Output is correct |
4 | Correct | 116 ms | 12152 KB | Output is correct |
5 | Correct | 115 ms | 11668 KB | Output is correct |
6 | Correct | 124 ms | 11896 KB | Output is correct |
7 | Correct | 111 ms | 11896 KB | Output is correct |
8 | Correct | 102 ms | 10744 KB | Output is correct |
9 | Correct | 113 ms | 10688 KB | Output is correct |
10 | Correct | 103 ms | 10824 KB | Output is correct |
11 | Correct | 82 ms | 10616 KB | Output is correct |
12 | Correct | 86 ms | 10940 KB | Output is correct |
13 | Correct | 83 ms | 10624 KB | Output is correct |
14 | Correct | 118 ms | 15040 KB | Output is correct |
15 | Correct | 101 ms | 10616 KB | Output is correct |
16 | Correct | 83 ms | 10616 KB | Output is correct |
17 | Correct | 156 ms | 17400 KB | Output is correct |
18 | Correct | 110 ms | 11000 KB | Output is correct |
19 | Correct | 115 ms | 10744 KB | Output is correct |
20 | Correct | 109 ms | 12792 KB | Output is correct |
21 | Correct | 129 ms | 10744 KB | Output is correct |
22 | Correct | 134 ms | 10616 KB | Output is correct |
23 | Correct | 125 ms | 10872 KB | Output is correct |
24 | Correct | 128 ms | 10616 KB | Output is correct |
25 | Correct | 129 ms | 10876 KB | Output is correct |
26 | Correct | 137 ms | 10888 KB | Output is correct |
27 | Correct | 141 ms | 10876 KB | Output is correct |
28 | Correct | 126 ms | 10748 KB | Output is correct |
29 | Correct | 131 ms | 10872 KB | Output is correct |
30 | Correct | 141 ms | 11000 KB | Output is correct |
31 | Correct | 0 ms | 384 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 384 KB | Output is correct |
34 | Correct | 1 ms | 384 KB | Output is correct |
35 | Correct | 0 ms | 384 KB | Output is correct |
36 | Correct | 1 ms | 384 KB | Output is correct |
37 | Correct | 1 ms | 384 KB | Output is correct |
38 | Correct | 1 ms | 384 KB | Output is correct |
39 | Correct | 1 ms | 384 KB | Output is correct |
40 | Correct | 0 ms | 384 KB | Output is correct |
41 | Correct | 1 ms | 384 KB | Output is correct |
42 | Correct | 1 ms | 384 KB | Output is correct |
43 | Correct | 1 ms | 384 KB | Output is correct |
44 | Correct | 1 ms | 384 KB | Output is correct |
45 | Correct | 1 ms | 384 KB | Output is correct |
46 | Correct | 1 ms | 384 KB | Output is correct |
47 | Correct | 1 ms | 384 KB | Output is correct |
48 | Correct | 1 ms | 384 KB | Output is correct |
49 | Correct | 1 ms | 384 KB | Output is correct |
50 | Correct | 1 ms | 384 KB | Output is correct |
51 | Correct | 1 ms | 384 KB | Output is correct |
52 | Correct | 2 ms | 432 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 1 ms | 384 KB | Output is correct |
55 | Correct | 1 ms | 384 KB | Output is correct |
56 | Correct | 1 ms | 384 KB | Output is correct |
57 | Correct | 1 ms | 512 KB | Output is correct |
58 | Correct | 1 ms | 384 KB | Output is correct |
59 | Correct | 2 ms | 384 KB | Output is correct |
60 | Correct | 1 ms | 384 KB | Output is correct |
61 | Correct | 183 ms | 15356 KB | Output is correct |
62 | Correct | 195 ms | 17984 KB | Output is correct |
63 | Correct | 140 ms | 13792 KB | Output is correct |
64 | Correct | 198 ms | 15544 KB | Output is correct |
65 | Correct | 195 ms | 14840 KB | Output is correct |
66 | Correct | 178 ms | 14712 KB | Output is correct |
67 | Correct | 170 ms | 14584 KB | Output is correct |
68 | Correct | 144 ms | 13944 KB | Output is correct |
69 | Correct | 135 ms | 13560 KB | Output is correct |
70 | Correct | 127 ms | 13528 KB | Output is correct |