Submission #721251

# Submission time Handle Problem Language Result Execution time Memory
721251 2023-04-10T14:41:30 Z NeroZein Feast (NOI19_feast) C++17
100 / 100
156 ms 10868 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 300005;

int n, k;
int a[N];
pair<long long,int> dp[N][2];
pair<long long,int> solve (long long cost) {
	dp[0][0] = {0LL, 0};
	dp[0][1] = {-1e15, -N};
	for (int i = 1; i <= n; ++i) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][1] = max(make_pair(dp[i - 1][0].first + a[i] - cost, dp[i - 1][0].second + 1), 
									 make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second)); 
	}
	return max(dp[n][0], dp[n][1]); 
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	long long l = 0, r = (long long) N * 1e9;
	while (l < r) {
		long long mid = (l + r) >> 1;
		if (solve(mid).second > k) {
			l = mid + 1;
		} else {
			r = mid;
		}
	}
	cout << solve(l).first + l * k << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10572 KB Output is correct
2 Correct 92 ms 10744 KB Output is correct
3 Correct 96 ms 10800 KB Output is correct
4 Correct 98 ms 10784 KB Output is correct
5 Correct 98 ms 10728 KB Output is correct
6 Correct 92 ms 10556 KB Output is correct
7 Correct 87 ms 10444 KB Output is correct
8 Correct 86 ms 10760 KB Output is correct
9 Correct 89 ms 10460 KB Output is correct
10 Correct 89 ms 10708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 10620 KB Output is correct
2 Correct 86 ms 10784 KB Output is correct
3 Correct 76 ms 10580 KB Output is correct
4 Correct 83 ms 10696 KB Output is correct
5 Correct 89 ms 10588 KB Output is correct
6 Correct 79 ms 10580 KB Output is correct
7 Correct 93 ms 10772 KB Output is correct
8 Correct 90 ms 10700 KB Output is correct
9 Correct 89 ms 10528 KB Output is correct
10 Correct 78 ms 10792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 10676 KB Output is correct
2 Correct 110 ms 10640 KB Output is correct
3 Correct 101 ms 10724 KB Output is correct
4 Correct 105 ms 10628 KB Output is correct
5 Correct 113 ms 10716 KB Output is correct
6 Correct 106 ms 10784 KB Output is correct
7 Correct 102 ms 10700 KB Output is correct
8 Correct 102 ms 10640 KB Output is correct
9 Correct 106 ms 10860 KB Output is correct
10 Correct 102 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10572 KB Output is correct
2 Correct 92 ms 10744 KB Output is correct
3 Correct 96 ms 10800 KB Output is correct
4 Correct 98 ms 10784 KB Output is correct
5 Correct 98 ms 10728 KB Output is correct
6 Correct 92 ms 10556 KB Output is correct
7 Correct 87 ms 10444 KB Output is correct
8 Correct 86 ms 10760 KB Output is correct
9 Correct 89 ms 10460 KB Output is correct
10 Correct 89 ms 10708 KB Output is correct
11 Correct 81 ms 10620 KB Output is correct
12 Correct 86 ms 10784 KB Output is correct
13 Correct 76 ms 10580 KB Output is correct
14 Correct 83 ms 10696 KB Output is correct
15 Correct 89 ms 10588 KB Output is correct
16 Correct 79 ms 10580 KB Output is correct
17 Correct 93 ms 10772 KB Output is correct
18 Correct 90 ms 10700 KB Output is correct
19 Correct 89 ms 10528 KB Output is correct
20 Correct 78 ms 10792 KB Output is correct
21 Correct 118 ms 10676 KB Output is correct
22 Correct 110 ms 10640 KB Output is correct
23 Correct 101 ms 10724 KB Output is correct
24 Correct 105 ms 10628 KB Output is correct
25 Correct 113 ms 10716 KB Output is correct
26 Correct 106 ms 10784 KB Output is correct
27 Correct 102 ms 10700 KB Output is correct
28 Correct 102 ms 10640 KB Output is correct
29 Correct 106 ms 10860 KB Output is correct
30 Correct 102 ms 10744 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 144 ms 10512 KB Output is correct
62 Correct 147 ms 10868 KB Output is correct
63 Correct 123 ms 10580 KB Output is correct
64 Correct 149 ms 10688 KB Output is correct
65 Correct 156 ms 10788 KB Output is correct
66 Correct 145 ms 10748 KB Output is correct
67 Correct 142 ms 10596 KB Output is correct
68 Correct 109 ms 10796 KB Output is correct
69 Correct 104 ms 10596 KB Output is correct
70 Correct 103 ms 10440 KB Output is correct