# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017157 |
2024-07-09T03:18:38 Z |
rxlfd314 |
Feast (NOI19_feast) |
C++17 |
|
604 ms |
23380 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ari2 = array<int, 2>;
using ari3 = array<int, 3>;
using ari4 = array<int, 4>;
using arl2 = array<ll, 2>;
using arl3 = array<ll, 3>;
using arl4 = array<ll, 4>;
#define vt vector
#define all(x) begin(x), end(x)
#define size(x) (int((x).size()))
#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)
void solve();
signed main() {
#ifndef DEBUG
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int T = 1;
//cin >> T;
FOR(t, 1, T) {
solve();
}
}
void solve() {
int N, K;
cin >> N >> K;
vt<int> A(N+1);
FOR(i, 1, N)
cin >> A[i];
vt<array<pair<ld, int>, 2>> dp(N+1);
auto calc = [&](ld pen) {
dp[0][1] = {-3e14, 0};
dp[0][0] = {0, 0};
FOR(i, 1, N) {
dp[i][1] = make_pair(dp[i-1][1].first + A[i], dp[i-1][1].second);
dp[i][1] = max(dp[i][1], make_pair(dp[i-1][0].first + A[i] - pen, dp[i-1][0].second - 1));
dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
}
};
ld lo = 0, hi = 3e14;
FOR(_, 1, 100) {
ld mid = (lo + hi) / 2.0;
calc(mid);
if (-max({dp[N][0], dp[N][1]}).second <= K)
hi = mid;
else
lo = mid;
}
calc(lo);
cout << (ll)round(max(dp[N][0], dp[N][1]).first + lo * K) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
22352 KB |
Output is correct |
2 |
Correct |
300 ms |
23112 KB |
Output is correct |
3 |
Correct |
320 ms |
23380 KB |
Output is correct |
4 |
Correct |
317 ms |
22876 KB |
Output is correct |
5 |
Correct |
312 ms |
22988 KB |
Output is correct |
6 |
Correct |
323 ms |
22612 KB |
Output is correct |
7 |
Correct |
312 ms |
22596 KB |
Output is correct |
8 |
Correct |
299 ms |
22868 KB |
Output is correct |
9 |
Correct |
303 ms |
22608 KB |
Output is correct |
10 |
Correct |
300 ms |
22876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
21060 KB |
Output is correct |
2 |
Correct |
308 ms |
21504 KB |
Output is correct |
3 |
Correct |
304 ms |
21008 KB |
Output is correct |
4 |
Correct |
282 ms |
21072 KB |
Output is correct |
5 |
Correct |
291 ms |
22452 KB |
Output is correct |
6 |
Correct |
303 ms |
20820 KB |
Output is correct |
7 |
Correct |
303 ms |
21544 KB |
Output is correct |
8 |
Correct |
287 ms |
23124 KB |
Output is correct |
9 |
Correct |
298 ms |
22360 KB |
Output is correct |
10 |
Correct |
292 ms |
21396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
23124 KB |
Output is correct |
2 |
Correct |
379 ms |
22876 KB |
Output is correct |
3 |
Correct |
365 ms |
23140 KB |
Output is correct |
4 |
Correct |
372 ms |
22864 KB |
Output is correct |
5 |
Correct |
379 ms |
23120 KB |
Output is correct |
6 |
Correct |
366 ms |
23120 KB |
Output is correct |
7 |
Correct |
394 ms |
23124 KB |
Output is correct |
8 |
Correct |
369 ms |
23120 KB |
Output is correct |
9 |
Correct |
402 ms |
23376 KB |
Output is correct |
10 |
Correct |
382 ms |
23364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
608 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
488 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
608 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
22352 KB |
Output is correct |
2 |
Correct |
300 ms |
23112 KB |
Output is correct |
3 |
Correct |
320 ms |
23380 KB |
Output is correct |
4 |
Correct |
317 ms |
22876 KB |
Output is correct |
5 |
Correct |
312 ms |
22988 KB |
Output is correct |
6 |
Correct |
323 ms |
22612 KB |
Output is correct |
7 |
Correct |
312 ms |
22596 KB |
Output is correct |
8 |
Correct |
299 ms |
22868 KB |
Output is correct |
9 |
Correct |
303 ms |
22608 KB |
Output is correct |
10 |
Correct |
300 ms |
22876 KB |
Output is correct |
11 |
Correct |
303 ms |
21060 KB |
Output is correct |
12 |
Correct |
308 ms |
21504 KB |
Output is correct |
13 |
Correct |
304 ms |
21008 KB |
Output is correct |
14 |
Correct |
282 ms |
21072 KB |
Output is correct |
15 |
Correct |
291 ms |
22452 KB |
Output is correct |
16 |
Correct |
303 ms |
20820 KB |
Output is correct |
17 |
Correct |
303 ms |
21544 KB |
Output is correct |
18 |
Correct |
287 ms |
23124 KB |
Output is correct |
19 |
Correct |
298 ms |
22360 KB |
Output is correct |
20 |
Correct |
292 ms |
21396 KB |
Output is correct |
21 |
Correct |
399 ms |
23124 KB |
Output is correct |
22 |
Correct |
379 ms |
22876 KB |
Output is correct |
23 |
Correct |
365 ms |
23140 KB |
Output is correct |
24 |
Correct |
372 ms |
22864 KB |
Output is correct |
25 |
Correct |
379 ms |
23120 KB |
Output is correct |
26 |
Correct |
366 ms |
23120 KB |
Output is correct |
27 |
Correct |
394 ms |
23124 KB |
Output is correct |
28 |
Correct |
369 ms |
23120 KB |
Output is correct |
29 |
Correct |
402 ms |
23376 KB |
Output is correct |
30 |
Correct |
382 ms |
23364 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
452 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
452 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
3 ms |
604 KB |
Output is correct |
52 |
Correct |
3 ms |
608 KB |
Output is correct |
53 |
Correct |
2 ms |
604 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
4 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
488 KB |
Output is correct |
57 |
Correct |
2 ms |
600 KB |
Output is correct |
58 |
Correct |
3 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
608 KB |
Output is correct |
60 |
Correct |
3 ms |
348 KB |
Output is correct |
61 |
Correct |
581 ms |
22716 KB |
Output is correct |
62 |
Correct |
540 ms |
23256 KB |
Output is correct |
63 |
Correct |
463 ms |
22864 KB |
Output is correct |
64 |
Correct |
604 ms |
23124 KB |
Output is correct |
65 |
Correct |
572 ms |
23248 KB |
Output is correct |
66 |
Correct |
587 ms |
23124 KB |
Output is correct |
67 |
Correct |
585 ms |
22864 KB |
Output is correct |
68 |
Correct |
402 ms |
23128 KB |
Output is correct |
69 |
Correct |
400 ms |
22848 KB |
Output is correct |
70 |
Correct |
384 ms |
22704 KB |
Output is correct |