Submission #676480

# Submission time Handle Problem Language Result Execution time Memory
676480 2022-12-31T03:35:41 Z penguin133 Feast (NOI19_feast) C++17
100 / 100
152 ms 15100 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#define getchar_unlocked _getchar_nolock

int n, k, A[300005];
pi dp[300005][2];
int ans;

int c(int x){
	dp[0][0] = {0, 0};
	dp[0][1] = {-1e18, 0};
	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].fi + A[i] - x, dp[i-1][0].se + 1), make_pair(dp[i-1][1].fi + A[i], dp[i-1][1].se)});
	}
	pi tmp = max(dp[n][0], dp[n][1]);
	if(tmp.se <= k)ans = max(ans, tmp.fi + tmp.se * x);
	cerr << x << " " << tmp.fi << " " << tmp.se << '\n';
	return tmp.se;
}


void solve(){
	cin >> n >> k;
	for(int i=1;i<=n;i++)cin >> A[i];
	int lo = 0, hi = 1e15;
	while(lo <= hi){
		int mid = (lo + hi) >> 1;
		if(c(mid) >= k)lo = mid + 1;
		else hi = mid - 1;
	}
	cout << ans;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	while(tc--){
		solve();
	}
}

Compilation message

feast.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 97 ms 14480 KB Output is correct
2 Correct 93 ms 14748 KB Output is correct
3 Correct 93 ms 15028 KB Output is correct
4 Correct 95 ms 14796 KB Output is correct
5 Correct 97 ms 14660 KB Output is correct
6 Correct 89 ms 14492 KB Output is correct
7 Correct 90 ms 14488 KB Output is correct
8 Correct 98 ms 14668 KB Output is correct
9 Correct 100 ms 14508 KB Output is correct
10 Correct 91 ms 14668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 12872 KB Output is correct
2 Correct 89 ms 13164 KB Output is correct
3 Correct 85 ms 12748 KB Output is correct
4 Correct 83 ms 12952 KB Output is correct
5 Correct 94 ms 14448 KB Output is correct
6 Correct 84 ms 12856 KB Output is correct
7 Correct 83 ms 13184 KB Output is correct
8 Correct 103 ms 14792 KB Output is correct
9 Correct 92 ms 14412 KB Output is correct
10 Correct 83 ms 13092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 14820 KB Output is correct
2 Correct 112 ms 14748 KB Output is correct
3 Correct 108 ms 14952 KB Output is correct
4 Correct 103 ms 14664 KB Output is correct
5 Correct 104 ms 14856 KB Output is correct
6 Correct 104 ms 15060 KB Output is correct
7 Correct 104 ms 14932 KB Output is correct
8 Correct 132 ms 14868 KB Output is correct
9 Correct 111 ms 15080 KB Output is correct
10 Correct 125 ms 15040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 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 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 328 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 328 KB Output is correct
18 Correct 2 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 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 328 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 328 KB Output is correct
18 Correct 2 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 4 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 432 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 14480 KB Output is correct
2 Correct 93 ms 14748 KB Output is correct
3 Correct 93 ms 15028 KB Output is correct
4 Correct 95 ms 14796 KB Output is correct
5 Correct 97 ms 14660 KB Output is correct
6 Correct 89 ms 14492 KB Output is correct
7 Correct 90 ms 14488 KB Output is correct
8 Correct 98 ms 14668 KB Output is correct
9 Correct 100 ms 14508 KB Output is correct
10 Correct 91 ms 14668 KB Output is correct
11 Correct 82 ms 12872 KB Output is correct
12 Correct 89 ms 13164 KB Output is correct
13 Correct 85 ms 12748 KB Output is correct
14 Correct 83 ms 12952 KB Output is correct
15 Correct 94 ms 14448 KB Output is correct
16 Correct 84 ms 12856 KB Output is correct
17 Correct 83 ms 13184 KB Output is correct
18 Correct 103 ms 14792 KB Output is correct
19 Correct 92 ms 14412 KB Output is correct
20 Correct 83 ms 13092 KB Output is correct
21 Correct 103 ms 14820 KB Output is correct
22 Correct 112 ms 14748 KB Output is correct
23 Correct 108 ms 14952 KB Output is correct
24 Correct 103 ms 14664 KB Output is correct
25 Correct 104 ms 14856 KB Output is correct
26 Correct 104 ms 15060 KB Output is correct
27 Correct 104 ms 14932 KB Output is correct
28 Correct 132 ms 14868 KB Output is correct
29 Correct 111 ms 15080 KB Output is correct
30 Correct 125 ms 15040 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 328 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 328 KB Output is correct
48 Correct 2 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 4 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 3 ms 432 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 2 ms 336 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 2 ms 340 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 152 ms 14736 KB Output is correct
62 Correct 140 ms 15100 KB Output is correct
63 Correct 137 ms 14672 KB Output is correct
64 Correct 145 ms 14984 KB Output is correct
65 Correct 143 ms 14868 KB Output is correct
66 Correct 142 ms 14844 KB Output is correct
67 Correct 145 ms 14716 KB Output is correct
68 Correct 129 ms 15000 KB Output is correct
69 Correct 134 ms 14612 KB Output is correct
70 Correct 125 ms 14640 KB Output is correct