# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1113207 | 2024-11-16T03:48:54 Z | HiepVu217 | Feast (NOI19_feast) | C++17 | 137 ms | 10220 KB |
#include <bits/stdc++.h> #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; const int N = 3e5 + 17; int n, k; long long a[N]; pair <long long, int> f[N], m; inline pair <long long, int> calc (long long c) { f[0] = m = {0, 0}; for (int i = 1; i <= n; ++i) { f[i] = f[i - 1]; if (m.first + a[i] - c > f[i].first || (m.first + a[i] - c == f[i].first && m.second + 1 < f[i].second)) { f[i].first = m.first + a[i] - c; f[i].second = m.second + 1; } if (f[i].first - a[i] > m.first || (f[i].first - a[i] == m.first && f[i].second < m.second)) { m.first = f[i].first - a[i]; m.second = f[i].second; } } return f[n]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i - 1]; } long long l = 1, r = 3e14; while (l < r) { long long mid = l + r + 1 >> 1; m = calc (mid); if (m.second >= k) { l = mid; continue; } r = mid - 1; } m = calc(l); long long ans = l * m.second + m.first; cout << ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 7248 KB | Output is correct |
2 | Correct | 46 ms | 7240 KB | Output is correct |
3 | Correct | 65 ms | 7380 KB | Output is correct |
4 | Correct | 79 ms | 7440 KB | Output is correct |
5 | Correct | 48 ms | 7248 KB | Output is correct |
6 | Correct | 50 ms | 7248 KB | Output is correct |
7 | Correct | 73 ms | 7244 KB | Output is correct |
8 | Correct | 75 ms | 7240 KB | Output is correct |
9 | Correct | 57 ms | 7228 KB | Output is correct |
10 | Correct | 50 ms | 7248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 7248 KB | Output is correct |
2 | Correct | 77 ms | 7240 KB | Output is correct |
3 | Correct | 38 ms | 7248 KB | Output is correct |
4 | Correct | 39 ms | 7248 KB | Output is correct |
5 | Correct | 53 ms | 7268 KB | Output is correct |
6 | Correct | 36 ms | 7248 KB | Output is correct |
7 | Correct | 37 ms | 7504 KB | Output is correct |
8 | Correct | 43 ms | 7240 KB | Output is correct |
9 | Correct | 45 ms | 7240 KB | Output is correct |
10 | Correct | 37 ms | 7376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7248 KB | Output is correct |
2 | Correct | 65 ms | 7232 KB | Output is correct |
3 | Correct | 63 ms | 7168 KB | Output is correct |
4 | Correct | 68 ms | 7164 KB | Output is correct |
5 | Correct | 79 ms | 7272 KB | Output is correct |
6 | Correct | 61 ms | 7444 KB | Output is correct |
7 | Correct | 68 ms | 7440 KB | Output is correct |
8 | Correct | 67 ms | 7404 KB | Output is correct |
9 | Correct | 74 ms | 7240 KB | Output is correct |
10 | Correct | 66 ms | 7244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 464 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 464 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 636 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 1 ms | 592 KB | Output is correct |
19 | Correct | 1 ms | 336 KB | Output is correct |
20 | Correct | 1 ms | 336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 464 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 636 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 1 ms | 592 KB | Output is correct |
19 | Correct | 1 ms | 336 KB | Output is correct |
20 | Correct | 1 ms | 336 KB | Output is correct |
21 | Correct | 2 ms | 336 KB | Output is correct |
22 | Correct | 2 ms | 336 KB | Output is correct |
23 | Correct | 2 ms | 504 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
26 | Correct | 1 ms | 512 KB | Output is correct |
27 | Correct | 2 ms | 340 KB | Output is correct |
28 | Correct | 2 ms | 340 KB | Output is correct |
29 | Correct | 2 ms | 336 KB | Output is correct |
30 | Correct | 1 ms | 336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 7248 KB | Output is correct |
2 | Correct | 46 ms | 7240 KB | Output is correct |
3 | Correct | 65 ms | 7380 KB | Output is correct |
4 | Correct | 79 ms | 7440 KB | Output is correct |
5 | Correct | 48 ms | 7248 KB | Output is correct |
6 | Correct | 50 ms | 7248 KB | Output is correct |
7 | Correct | 73 ms | 7244 KB | Output is correct |
8 | Correct | 75 ms | 7240 KB | Output is correct |
9 | Correct | 57 ms | 7228 KB | Output is correct |
10 | Correct | 50 ms | 7248 KB | Output is correct |
11 | Correct | 38 ms | 7248 KB | Output is correct |
12 | Correct | 77 ms | 7240 KB | Output is correct |
13 | Correct | 38 ms | 7248 KB | Output is correct |
14 | Correct | 39 ms | 7248 KB | Output is correct |
15 | Correct | 53 ms | 7268 KB | Output is correct |
16 | Correct | 36 ms | 7248 KB | Output is correct |
17 | Correct | 37 ms | 7504 KB | Output is correct |
18 | Correct | 43 ms | 7240 KB | Output is correct |
19 | Correct | 45 ms | 7240 KB | Output is correct |
20 | Correct | 37 ms | 7376 KB | Output is correct |
21 | Correct | 64 ms | 7248 KB | Output is correct |
22 | Correct | 65 ms | 7232 KB | Output is correct |
23 | Correct | 63 ms | 7168 KB | Output is correct |
24 | Correct | 68 ms | 7164 KB | Output is correct |
25 | Correct | 79 ms | 7272 KB | Output is correct |
26 | Correct | 61 ms | 7444 KB | Output is correct |
27 | Correct | 68 ms | 7440 KB | Output is correct |
28 | Correct | 67 ms | 7404 KB | Output is correct |
29 | Correct | 74 ms | 7240 KB | Output is correct |
30 | Correct | 66 ms | 7244 KB | Output is correct |
31 | Correct | 2 ms | 336 KB | Output is correct |
32 | Correct | 1 ms | 336 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 512 KB | Output is correct |
35 | Correct | 1 ms | 336 KB | Output is correct |
36 | Correct | 1 ms | 336 KB | Output is correct |
37 | Correct | 1 ms | 464 KB | Output is correct |
38 | Correct | 1 ms | 336 KB | Output is correct |
39 | Correct | 1 ms | 336 KB | Output is correct |
40 | Correct | 1 ms | 336 KB | Output is correct |
41 | Correct | 1 ms | 336 KB | Output is correct |
42 | Correct | 1 ms | 636 KB | Output is correct |
43 | Correct | 1 ms | 336 KB | Output is correct |
44 | Correct | 1 ms | 336 KB | Output is correct |
45 | Correct | 1 ms | 336 KB | Output is correct |
46 | Correct | 1 ms | 336 KB | Output is correct |
47 | Correct | 1 ms | 336 KB | Output is correct |
48 | Correct | 1 ms | 592 KB | Output is correct |
49 | Correct | 1 ms | 336 KB | Output is correct |
50 | Correct | 1 ms | 336 KB | Output is correct |
51 | Correct | 2 ms | 336 KB | Output is correct |
52 | Correct | 2 ms | 336 KB | Output is correct |
53 | Correct | 2 ms | 504 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 336 KB | Output is correct |
56 | Correct | 1 ms | 512 KB | Output is correct |
57 | Correct | 2 ms | 340 KB | Output is correct |
58 | Correct | 2 ms | 340 KB | Output is correct |
59 | Correct | 2 ms | 336 KB | Output is correct |
60 | Correct | 1 ms | 336 KB | Output is correct |
61 | Correct | 109 ms | 9176 KB | Output is correct |
62 | Correct | 111 ms | 9948 KB | Output is correct |
63 | Correct | 84 ms | 9648 KB | Output is correct |
64 | Correct | 118 ms | 10056 KB | Output is correct |
65 | Correct | 137 ms | 9612 KB | Output is correct |
66 | Correct | 106 ms | 10056 KB | Output is correct |
67 | Correct | 111 ms | 9872 KB | Output is correct |
68 | Correct | 71 ms | 10220 KB | Output is correct |
69 | Correct | 67 ms | 10056 KB | Output is correct |
70 | Correct | 79 ms | 9760 KB | Output is correct |