Submission #739796

# Submission time Handle Problem Language Result Execution time Memory
739796 2023-05-11T10:05:24 Z NeroZein Feast (NOI19_feast) C++17
100 / 100
148 ms 13964 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;
		}
	}
	if (solve(l - 1).second == k) {
      cout << solve(l - 1).first + (l - 1) * k << '\n';
    } else {
      cout << solve(l).first + l * k << '\n';
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10544 KB Output is correct
2 Correct 90 ms 13600 KB Output is correct
3 Correct 89 ms 13744 KB Output is correct
4 Correct 92 ms 13644 KB Output is correct
5 Correct 93 ms 13712 KB Output is correct
6 Correct 88 ms 13256 KB Output is correct
7 Correct 86 ms 13260 KB Output is correct
8 Correct 85 ms 13564 KB Output is correct
9 Correct 86 ms 13312 KB Output is correct
10 Correct 84 ms 13524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 10612 KB Output is correct
2 Correct 83 ms 10848 KB Output is correct
3 Correct 79 ms 10604 KB Output is correct
4 Correct 77 ms 10708 KB Output is correct
5 Correct 92 ms 13476 KB Output is correct
6 Correct 83 ms 11676 KB Output is correct
7 Correct 81 ms 11940 KB Output is correct
8 Correct 87 ms 13616 KB Output is correct
9 Correct 83 ms 13316 KB Output is correct
10 Correct 86 ms 11936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 10752 KB Output is correct
2 Correct 102 ms 10596 KB Output is correct
3 Correct 106 ms 10736 KB Output is correct
4 Correct 100 ms 10572 KB Output is correct
5 Correct 98 ms 10708 KB Output is correct
6 Correct 106 ms 10700 KB Output is correct
7 Correct 104 ms 10828 KB Output is correct
8 Correct 102 ms 10700 KB Output is correct
9 Correct 107 ms 10856 KB Output is correct
10 Correct 104 ms 10780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 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 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 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 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 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 89 ms 10544 KB Output is correct
2 Correct 90 ms 13600 KB Output is correct
3 Correct 89 ms 13744 KB Output is correct
4 Correct 92 ms 13644 KB Output is correct
5 Correct 93 ms 13712 KB Output is correct
6 Correct 88 ms 13256 KB Output is correct
7 Correct 86 ms 13260 KB Output is correct
8 Correct 85 ms 13564 KB Output is correct
9 Correct 86 ms 13312 KB Output is correct
10 Correct 84 ms 13524 KB Output is correct
11 Correct 74 ms 10612 KB Output is correct
12 Correct 83 ms 10848 KB Output is correct
13 Correct 79 ms 10604 KB Output is correct
14 Correct 77 ms 10708 KB Output is correct
15 Correct 92 ms 13476 KB Output is correct
16 Correct 83 ms 11676 KB Output is correct
17 Correct 81 ms 11940 KB Output is correct
18 Correct 87 ms 13616 KB Output is correct
19 Correct 83 ms 13316 KB Output is correct
20 Correct 86 ms 11936 KB Output is correct
21 Correct 100 ms 10752 KB Output is correct
22 Correct 102 ms 10596 KB Output is correct
23 Correct 106 ms 10736 KB Output is correct
24 Correct 100 ms 10572 KB Output is correct
25 Correct 98 ms 10708 KB Output is correct
26 Correct 106 ms 10700 KB Output is correct
27 Correct 104 ms 10828 KB Output is correct
28 Correct 102 ms 10700 KB Output is correct
29 Correct 107 ms 10856 KB Output is correct
30 Correct 104 ms 10780 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 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 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 1 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 324 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 328 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 148 ms 13568 KB Output is correct
62 Correct 140 ms 13964 KB Output is correct
63 Correct 112 ms 13556 KB Output is correct
64 Correct 140 ms 13832 KB Output is correct
65 Correct 141 ms 13828 KB Output is correct
66 Correct 140 ms 13828 KB Output is correct
67 Correct 137 ms 13580 KB Output is correct
68 Correct 106 ms 13804 KB Output is correct
69 Correct 101 ms 13628 KB Output is correct
70 Correct 98 ms 13396 KB Output is correct