Submission #588025

# Submission time Handle Problem Language Result Execution time Memory
588025 2022-07-02T16:14:54 Z sofapuden Feast (NOI19_feast) C++14
100 / 100
181 ms 26840 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mn = -(1ll<<60);

void solve(){
	int n, k; cin >> n >> k;
	vector<ll> v(n);
	for(auto &x : v)cin >> x;
	ll l = 0, r = (1ll<<42), bes = 0;
	vector<vector<pair<ll,ll>>> dp(n,vector<pair<ll,ll>>(2));
	while(l<=r){
		ll m = (l+r)>>1;
		dp[0][0] = {0,0};
		dp[0][1] = {-m+v[0],1};
		for(int i = 1; i < n; ++i){
			dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
			dp[i][1] = max(dp[i-1][1],{dp[i-1][0].first-m,dp[i-1][0].second+1});
			dp[i][1].first+=v[i];
		}
		pair<ll,ll> b = max(dp[n-1][0], dp[n-1][1]);
		if(b.second > k){
			l = m+1;
		}
		else{
			r = m-1;
			bes = b.first + m*k;
		}
	}
	cout << bes << '\n';
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 129 ms 24396 KB Output is correct
2 Correct 137 ms 26352 KB Output is correct
3 Correct 161 ms 26572 KB Output is correct
4 Correct 131 ms 26468 KB Output is correct
5 Correct 146 ms 26264 KB Output is correct
6 Correct 135 ms 25760 KB Output is correct
7 Correct 127 ms 25920 KB Output is correct
8 Correct 140 ms 26408 KB Output is correct
9 Correct 153 ms 25932 KB Output is correct
10 Correct 134 ms 26204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 24192 KB Output is correct
2 Correct 122 ms 24000 KB Output is correct
3 Correct 118 ms 23448 KB Output is correct
4 Correct 129 ms 23616 KB Output is correct
5 Correct 147 ms 25904 KB Output is correct
6 Correct 131 ms 24288 KB Output is correct
7 Correct 135 ms 24908 KB Output is correct
8 Correct 134 ms 26508 KB Output is correct
9 Correct 135 ms 25820 KB Output is correct
10 Correct 125 ms 24820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 24932 KB Output is correct
2 Correct 138 ms 23488 KB Output is correct
3 Correct 145 ms 23720 KB Output is correct
4 Correct 143 ms 23468 KB Output is correct
5 Correct 142 ms 23612 KB Output is correct
6 Correct 181 ms 26560 KB Output is correct
7 Correct 145 ms 26724 KB Output is correct
8 Correct 143 ms 25504 KB Output is correct
9 Correct 153 ms 26780 KB Output is correct
10 Correct 155 ms 26728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 316 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 2 ms 456 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 456 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 24396 KB Output is correct
2 Correct 137 ms 26352 KB Output is correct
3 Correct 161 ms 26572 KB Output is correct
4 Correct 131 ms 26468 KB Output is correct
5 Correct 146 ms 26264 KB Output is correct
6 Correct 135 ms 25760 KB Output is correct
7 Correct 127 ms 25920 KB Output is correct
8 Correct 140 ms 26408 KB Output is correct
9 Correct 153 ms 25932 KB Output is correct
10 Correct 134 ms 26204 KB Output is correct
11 Correct 125 ms 24192 KB Output is correct
12 Correct 122 ms 24000 KB Output is correct
13 Correct 118 ms 23448 KB Output is correct
14 Correct 129 ms 23616 KB Output is correct
15 Correct 147 ms 25904 KB Output is correct
16 Correct 131 ms 24288 KB Output is correct
17 Correct 135 ms 24908 KB Output is correct
18 Correct 134 ms 26508 KB Output is correct
19 Correct 135 ms 25820 KB Output is correct
20 Correct 125 ms 24820 KB Output is correct
21 Correct 160 ms 24932 KB Output is correct
22 Correct 138 ms 23488 KB Output is correct
23 Correct 145 ms 23720 KB Output is correct
24 Correct 143 ms 23468 KB Output is correct
25 Correct 142 ms 23612 KB Output is correct
26 Correct 181 ms 26560 KB Output is correct
27 Correct 145 ms 26724 KB Output is correct
28 Correct 143 ms 25504 KB Output is correct
29 Correct 153 ms 26780 KB Output is correct
30 Correct 155 ms 26728 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 232 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Correct 0 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 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 320 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 324 KB Output is correct
48 Correct 0 ms 316 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 2 ms 456 KB Output is correct
56 Correct 6 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 456 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 160 ms 26180 KB Output is correct
62 Correct 164 ms 26840 KB Output is correct
63 Correct 141 ms 26120 KB Output is correct
64 Correct 160 ms 26576 KB Output is correct
65 Correct 172 ms 26620 KB Output is correct
66 Correct 160 ms 26556 KB Output is correct
67 Correct 179 ms 26264 KB Output is correct
68 Correct 150 ms 26656 KB Output is correct
69 Correct 152 ms 26132 KB Output is correct
70 Correct 136 ms 26008 KB Output is correct