Submission #901376

# Submission time Handle Problem Language Result Execution time Memory
901376 2024-01-09T11:20:39 Z pcc Feast (NOI19_feast) C++17
100 / 100
118 ms 12896 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const ll inf = 1e13;
const int mxn = 3e5+10;
ll arr[mxn];
ll pref[mxn];
pll dp[mxn];
ll N,K;

inline pll calc(ll p){
	pll pt = make_pair(0,0);
	for(int i = 1;i<=N;i++){
		dp[i] = dp[i-1];
		dp[i] = max(dp[i],make_pair(pref[i]+pt.fs-p,pt.sc+1));
		pt = max(pt,make_pair(dp[i].fs-pref[i],dp[i].sc));
	}
	return dp[N];
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>K;
	for(int i = 1;i<=N;i++){
		cin>>arr[i];
		pref[i] = arr[i]+pref[i-1];
	}
	ll l = -inf,r = inf;
	while(l != r){
		ll mid = l+(r-l+1)/2;
		if(calc(mid).sc>=K)l = mid;
		else r = mid-1;
	}
	auto re = calc(l);
	ll ans = re.fs+l*K;
	re = calc(0);
	if(re.sc<=K)ans = max(ans,re.fs);
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 62 ms 9608 KB Output is correct
2 Correct 65 ms 9744 KB Output is correct
3 Correct 64 ms 9824 KB Output is correct
4 Correct 64 ms 9776 KB Output is correct
5 Correct 70 ms 9552 KB Output is correct
6 Correct 63 ms 9564 KB Output is correct
7 Correct 64 ms 9672 KB Output is correct
8 Correct 63 ms 9552 KB Output is correct
9 Correct 65 ms 9632 KB Output is correct
10 Correct 63 ms 9472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 9564 KB Output is correct
2 Correct 78 ms 9816 KB Output is correct
3 Correct 74 ms 9564 KB Output is correct
4 Correct 63 ms 9716 KB Output is correct
5 Correct 64 ms 9628 KB Output is correct
6 Correct 72 ms 9640 KB Output is correct
7 Correct 63 ms 9820 KB Output is correct
8 Correct 66 ms 9556 KB Output is correct
9 Correct 63 ms 9596 KB Output is correct
10 Correct 63 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 9752 KB Output is correct
2 Correct 87 ms 12616 KB Output is correct
3 Correct 87 ms 12752 KB Output is correct
4 Correct 89 ms 12656 KB Output is correct
5 Correct 96 ms 12896 KB Output is correct
6 Correct 88 ms 12820 KB Output is correct
7 Correct 98 ms 12856 KB Output is correct
8 Correct 91 ms 12752 KB Output is correct
9 Correct 99 ms 12628 KB Output is correct
10 Correct 88 ms 12652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2548 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2548 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2560 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 9608 KB Output is correct
2 Correct 65 ms 9744 KB Output is correct
3 Correct 64 ms 9824 KB Output is correct
4 Correct 64 ms 9776 KB Output is correct
5 Correct 70 ms 9552 KB Output is correct
6 Correct 63 ms 9564 KB Output is correct
7 Correct 64 ms 9672 KB Output is correct
8 Correct 63 ms 9552 KB Output is correct
9 Correct 65 ms 9632 KB Output is correct
10 Correct 63 ms 9472 KB Output is correct
11 Correct 75 ms 9564 KB Output is correct
12 Correct 78 ms 9816 KB Output is correct
13 Correct 74 ms 9564 KB Output is correct
14 Correct 63 ms 9716 KB Output is correct
15 Correct 64 ms 9628 KB Output is correct
16 Correct 72 ms 9640 KB Output is correct
17 Correct 63 ms 9820 KB Output is correct
18 Correct 66 ms 9556 KB Output is correct
19 Correct 63 ms 9596 KB Output is correct
20 Correct 63 ms 9560 KB Output is correct
21 Correct 89 ms 9752 KB Output is correct
22 Correct 87 ms 12616 KB Output is correct
23 Correct 87 ms 12752 KB Output is correct
24 Correct 89 ms 12656 KB Output is correct
25 Correct 96 ms 12896 KB Output is correct
26 Correct 88 ms 12820 KB Output is correct
27 Correct 98 ms 12856 KB Output is correct
28 Correct 91 ms 12752 KB Output is correct
29 Correct 99 ms 12628 KB Output is correct
30 Correct 88 ms 12652 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2548 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 2 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2560 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 106 ms 12628 KB Output is correct
62 Correct 107 ms 12892 KB Output is correct
63 Correct 91 ms 12616 KB Output is correct
64 Correct 108 ms 12856 KB Output is correct
65 Correct 111 ms 12696 KB Output is correct
66 Correct 118 ms 12664 KB Output is correct
67 Correct 109 ms 12636 KB Output is correct
68 Correct 91 ms 12824 KB Output is correct
69 Correct 87 ms 12628 KB Output is correct
70 Correct 87 ms 12376 KB Output is correct