# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257497 | 2020-08-04T10:59:58 Z | karma | Feast (NOI19_feast) | C++14 | 182 ms | 11020 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; 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 | 107 ms | 10728 KB | Output is correct |
2 | Correct | 101 ms | 10744 KB | Output is correct |
3 | Correct | 106 ms | 10872 KB | Output is correct |
4 | Correct | 102 ms | 10872 KB | Output is correct |
5 | Correct | 114 ms | 10744 KB | Output is correct |
6 | Correct | 106 ms | 10616 KB | Output is correct |
7 | Correct | 99 ms | 10616 KB | Output is correct |
8 | Correct | 102 ms | 10744 KB | Output is correct |
9 | Correct | 101 ms | 10664 KB | Output is correct |
10 | Correct | 107 ms | 10872 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 10708 KB | Output is correct |
2 | Correct | 89 ms | 10856 KB | Output is correct |
3 | Correct | 86 ms | 10624 KB | Output is correct |
4 | Correct | 86 ms | 10752 KB | Output is correct |
5 | Correct | 104 ms | 10616 KB | Output is correct |
6 | Correct | 87 ms | 10616 KB | Output is correct |
7 | Correct | 101 ms | 10872 KB | Output is correct |
8 | Correct | 112 ms | 10872 KB | Output is correct |
9 | Correct | 106 ms | 10616 KB | Output is correct |
10 | Correct | 93 ms | 10872 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 10744 KB | Output is correct |
2 | Correct | 130 ms | 10656 KB | Output is correct |
3 | Correct | 129 ms | 10744 KB | Output is correct |
4 | Correct | 124 ms | 10616 KB | Output is correct |
5 | Correct | 125 ms | 10744 KB | Output is correct |
6 | Correct | 126 ms | 10872 KB | Output is correct |
7 | Correct | 182 ms | 11000 KB | Output is correct |
8 | Correct | 126 ms | 10748 KB | Output is correct |
9 | Correct | 130 ms | 10872 KB | Output is correct |
10 | Correct | 131 ms | 10792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 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 | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 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 | 1 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 | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 0 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 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 | 1 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 | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 0 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 1 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 | 384 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 107 ms | 10728 KB | Output is correct |
2 | Correct | 101 ms | 10744 KB | Output is correct |
3 | Correct | 106 ms | 10872 KB | Output is correct |
4 | Correct | 102 ms | 10872 KB | Output is correct |
5 | Correct | 114 ms | 10744 KB | Output is correct |
6 | Correct | 106 ms | 10616 KB | Output is correct |
7 | Correct | 99 ms | 10616 KB | Output is correct |
8 | Correct | 102 ms | 10744 KB | Output is correct |
9 | Correct | 101 ms | 10664 KB | Output is correct |
10 | Correct | 107 ms | 10872 KB | Output is correct |
11 | Correct | 90 ms | 10708 KB | Output is correct |
12 | Correct | 89 ms | 10856 KB | Output is correct |
13 | Correct | 86 ms | 10624 KB | Output is correct |
14 | Correct | 86 ms | 10752 KB | Output is correct |
15 | Correct | 104 ms | 10616 KB | Output is correct |
16 | Correct | 87 ms | 10616 KB | Output is correct |
17 | Correct | 101 ms | 10872 KB | Output is correct |
18 | Correct | 112 ms | 10872 KB | Output is correct |
19 | Correct | 106 ms | 10616 KB | Output is correct |
20 | Correct | 93 ms | 10872 KB | Output is correct |
21 | Correct | 146 ms | 10744 KB | Output is correct |
22 | Correct | 130 ms | 10656 KB | Output is correct |
23 | Correct | 129 ms | 10744 KB | Output is correct |
24 | Correct | 124 ms | 10616 KB | Output is correct |
25 | Correct | 125 ms | 10744 KB | Output is correct |
26 | Correct | 126 ms | 10872 KB | Output is correct |
27 | Correct | 182 ms | 11000 KB | Output is correct |
28 | Correct | 126 ms | 10748 KB | Output is correct |
29 | Correct | 130 ms | 10872 KB | Output is correct |
30 | Correct | 131 ms | 10792 KB | Output is correct |
31 | Correct | 0 ms | 384 KB | Output is correct |
32 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
37 | Correct | 0 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 | 1 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 | 0 ms | 384 KB | Output is correct |
44 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
48 | Correct | 1 ms | 384 KB | Output is correct |
49 | Correct | 0 ms | 384 KB | Output is correct |
50 | Correct | 0 ms | 384 KB | Output is correct |
51 | Correct | 1 ms | 384 KB | Output is correct |
52 | Correct | 2 ms | 384 KB | Output is correct |
53 | Correct | 1 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 | 384 KB | Output is correct |
58 | Correct | 1 ms | 384 KB | Output is correct |
59 | Correct | 1 ms | 384 KB | Output is correct |
60 | Correct | 1 ms | 384 KB | Output is correct |
61 | Correct | 165 ms | 10692 KB | Output is correct |
62 | Correct | 162 ms | 11020 KB | Output is correct |
63 | Correct | 137 ms | 10616 KB | Output is correct |
64 | Correct | 173 ms | 11000 KB | Output is correct |
65 | Correct | 178 ms | 10756 KB | Output is correct |
66 | Correct | 171 ms | 10876 KB | Output is correct |
67 | Correct | 178 ms | 10616 KB | Output is correct |
68 | Correct | 145 ms | 10872 KB | Output is correct |
69 | Correct | 129 ms | 10616 KB | Output is correct |
70 | Correct | 143 ms | 10616 KB | Output is correct |