Submission #1100192

# Submission time Handle Problem Language Result Execution time Memory
1100192 2024-10-13T09:26:27 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
136 ms 15252 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
const int N = 3e5 + 5, mod = 1e9 + 7;
ll arr[N];
ll dp[2][N], cnt[2][N];
int32_t main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	ll mn = -1e16;
	ll ans = mn;
	ll lo = mn, hi = -mn;
	while(lo <= hi) {
		ll mi = (lo + hi) / 2;
		dp[1][0] = mn;
		cnt[1][0] = 1;
		for(int i = 1; i <= n; i++) {
			dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]);
			if(dp[0][i - 1] > dp[1][i - 1])
				cnt[0][i] = cnt[0][i - 1];
			else
				cnt[0][i] = cnt[1][i - 1];

			dp[1][i] = max(dp[0][i - 1] - mi, dp[1][i - 1]) + arr[i];
			if(dp[0][i - 1] - mi > dp[1][i - 1]) 
				cnt[1][i] = cnt[0][i - 1] + 1;
			else cnt[1][i] = cnt[1][i - 1];
		}
		int part;
		ll cost;
		if(dp[0][n] >= dp[1][n]) {
			part = cnt[0][n]; 
			cost = dp[0][n] + part * mi;
		}
		else {
			part = cnt[1][n];
			cost = dp[1][n] + part * mi;
		}

		if(part <= k) ans = max(ans, cost), hi = mi - 1;
		else lo = mi + 1; 
	}
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14668 KB Output is correct
2 Correct 55 ms 14924 KB Output is correct
3 Correct 54 ms 14924 KB Output is correct
4 Correct 54 ms 14932 KB Output is correct
5 Correct 53 ms 14924 KB Output is correct
6 Correct 55 ms 14676 KB Output is correct
7 Correct 49 ms 14668 KB Output is correct
8 Correct 60 ms 14924 KB Output is correct
9 Correct 59 ms 14668 KB Output is correct
10 Correct 58 ms 14956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 13140 KB Output is correct
2 Correct 50 ms 13140 KB Output is correct
3 Correct 45 ms 13140 KB Output is correct
4 Correct 43 ms 13308 KB Output is correct
5 Correct 54 ms 14792 KB Output is correct
6 Correct 46 ms 13140 KB Output is correct
7 Correct 49 ms 13140 KB Output is correct
8 Correct 53 ms 14832 KB Output is correct
9 Correct 54 ms 14668 KB Output is correct
10 Correct 48 ms 13140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 14932 KB Output is correct
2 Correct 76 ms 14924 KB Output is correct
3 Correct 73 ms 14920 KB Output is correct
4 Correct 78 ms 14924 KB Output is correct
5 Correct 73 ms 14932 KB Output is correct
6 Correct 81 ms 14992 KB Output is correct
7 Correct 73 ms 15188 KB Output is correct
8 Correct 72 ms 14924 KB Output is correct
9 Correct 73 ms 15180 KB Output is correct
10 Correct 74 ms 15180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 2 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 1 ms 6484 KB Output is correct
6 Correct 1 ms 6740 KB Output is correct
7 Correct 1 ms 6484 KB Output is correct
8 Correct 1 ms 6484 KB Output is correct
9 Correct 1 ms 6484 KB Output is correct
10 Correct 1 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 2 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 1 ms 6484 KB Output is correct
6 Correct 1 ms 6740 KB Output is correct
7 Correct 1 ms 6484 KB Output is correct
8 Correct 1 ms 6484 KB Output is correct
9 Correct 1 ms 6484 KB Output is correct
10 Correct 1 ms 6484 KB Output is correct
11 Correct 1 ms 6484 KB Output is correct
12 Correct 1 ms 6484 KB Output is correct
13 Correct 1 ms 6712 KB Output is correct
14 Correct 1 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 1 ms 6740 KB Output is correct
18 Correct 2 ms 6484 KB Output is correct
19 Correct 1 ms 6484 KB Output is correct
20 Correct 1 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 2 ms 6484 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 1 ms 6484 KB Output is correct
6 Correct 1 ms 6740 KB Output is correct
7 Correct 1 ms 6484 KB Output is correct
8 Correct 1 ms 6484 KB Output is correct
9 Correct 1 ms 6484 KB Output is correct
10 Correct 1 ms 6484 KB Output is correct
11 Correct 1 ms 6484 KB Output is correct
12 Correct 1 ms 6484 KB Output is correct
13 Correct 1 ms 6712 KB Output is correct
14 Correct 1 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 1 ms 6740 KB Output is correct
18 Correct 2 ms 6484 KB Output is correct
19 Correct 1 ms 6484 KB Output is correct
20 Correct 1 ms 6484 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6696 KB Output is correct
24 Correct 2 ms 6496 KB Output is correct
25 Correct 2 ms 6632 KB Output is correct
26 Correct 2 ms 6496 KB Output is correct
27 Correct 2 ms 6640 KB Output is correct
28 Correct 2 ms 6496 KB Output is correct
29 Correct 2 ms 6496 KB Output is correct
30 Correct 2 ms 6496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14668 KB Output is correct
2 Correct 55 ms 14924 KB Output is correct
3 Correct 54 ms 14924 KB Output is correct
4 Correct 54 ms 14932 KB Output is correct
5 Correct 53 ms 14924 KB Output is correct
6 Correct 55 ms 14676 KB Output is correct
7 Correct 49 ms 14668 KB Output is correct
8 Correct 60 ms 14924 KB Output is correct
9 Correct 59 ms 14668 KB Output is correct
10 Correct 58 ms 14956 KB Output is correct
11 Correct 45 ms 13140 KB Output is correct
12 Correct 50 ms 13140 KB Output is correct
13 Correct 45 ms 13140 KB Output is correct
14 Correct 43 ms 13308 KB Output is correct
15 Correct 54 ms 14792 KB Output is correct
16 Correct 46 ms 13140 KB Output is correct
17 Correct 49 ms 13140 KB Output is correct
18 Correct 53 ms 14832 KB Output is correct
19 Correct 54 ms 14668 KB Output is correct
20 Correct 48 ms 13140 KB Output is correct
21 Correct 87 ms 14932 KB Output is correct
22 Correct 76 ms 14924 KB Output is correct
23 Correct 73 ms 14920 KB Output is correct
24 Correct 78 ms 14924 KB Output is correct
25 Correct 73 ms 14932 KB Output is correct
26 Correct 81 ms 14992 KB Output is correct
27 Correct 73 ms 15188 KB Output is correct
28 Correct 72 ms 14924 KB Output is correct
29 Correct 73 ms 15180 KB Output is correct
30 Correct 74 ms 15180 KB Output is correct
31 Correct 1 ms 6484 KB Output is correct
32 Correct 2 ms 6484 KB Output is correct
33 Correct 2 ms 6484 KB Output is correct
34 Correct 1 ms 6484 KB Output is correct
35 Correct 1 ms 6484 KB Output is correct
36 Correct 1 ms 6740 KB Output is correct
37 Correct 1 ms 6484 KB Output is correct
38 Correct 1 ms 6484 KB Output is correct
39 Correct 1 ms 6484 KB Output is correct
40 Correct 1 ms 6484 KB Output is correct
41 Correct 1 ms 6484 KB Output is correct
42 Correct 1 ms 6484 KB Output is correct
43 Correct 1 ms 6712 KB Output is correct
44 Correct 1 ms 6484 KB Output is correct
45 Correct 2 ms 6484 KB Output is correct
46 Correct 2 ms 6484 KB Output is correct
47 Correct 1 ms 6740 KB Output is correct
48 Correct 2 ms 6484 KB Output is correct
49 Correct 1 ms 6484 KB Output is correct
50 Correct 1 ms 6484 KB Output is correct
51 Correct 2 ms 6484 KB Output is correct
52 Correct 2 ms 6484 KB Output is correct
53 Correct 2 ms 6696 KB Output is correct
54 Correct 2 ms 6496 KB Output is correct
55 Correct 2 ms 6632 KB Output is correct
56 Correct 2 ms 6496 KB Output is correct
57 Correct 2 ms 6640 KB Output is correct
58 Correct 2 ms 6496 KB Output is correct
59 Correct 2 ms 6496 KB Output is correct
60 Correct 2 ms 6496 KB Output is correct
61 Correct 121 ms 14936 KB Output is correct
62 Correct 58 ms 15252 KB Output is correct
63 Correct 90 ms 15152 KB Output is correct
64 Correct 118 ms 15196 KB Output is correct
65 Correct 112 ms 15200 KB Output is correct
66 Correct 136 ms 14940 KB Output is correct
67 Correct 116 ms 14924 KB Output is correct
68 Correct 80 ms 15172 KB Output is correct
69 Correct 84 ms 14932 KB Output is correct
70 Correct 74 ms 15100 KB Output is correct