Submission #901371

# Submission time Handle Problem Language Result Execution time Memory
901371 2024-01-09T11:17:30 Z pcc Feast (NOI19_feast) C++14
12 / 100
87 ms 12636 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 = 1e9+10;
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 52 ms 12404 KB Output is correct
2 Correct 52 ms 12384 KB Output is correct
3 Correct 53 ms 12624 KB Output is correct
4 Correct 54 ms 12636 KB Output is correct
5 Correct 53 ms 12368 KB Output is correct
6 Correct 51 ms 12368 KB Output is correct
7 Correct 52 ms 12188 KB Output is correct
8 Correct 52 ms 12624 KB Output is correct
9 Correct 51 ms 12368 KB Output is correct
10 Correct 55 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10588 KB Output is correct
2 Correct 58 ms 10960 KB Output is correct
3 Correct 59 ms 10588 KB Output is correct
4 Correct 45 ms 10840 KB Output is correct
5 Correct 52 ms 12628 KB Output is correct
6 Correct 57 ms 10588 KB Output is correct
7 Correct 47 ms 10800 KB Output is correct
8 Correct 54 ms 12632 KB Output is correct
9 Correct 55 ms 12400 KB Output is correct
10 Correct 50 ms 11088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 12404 KB Output is correct
2 Correct 52 ms 12384 KB Output is correct
3 Correct 53 ms 12624 KB Output is correct
4 Correct 54 ms 12636 KB Output is correct
5 Correct 53 ms 12368 KB Output is correct
6 Correct 51 ms 12368 KB Output is correct
7 Correct 52 ms 12188 KB Output is correct
8 Correct 52 ms 12624 KB Output is correct
9 Correct 51 ms 12368 KB Output is correct
10 Correct 55 ms 12628 KB Output is correct
11 Correct 57 ms 10588 KB Output is correct
12 Correct 58 ms 10960 KB Output is correct
13 Correct 59 ms 10588 KB Output is correct
14 Correct 45 ms 10840 KB Output is correct
15 Correct 52 ms 12628 KB Output is correct
16 Correct 57 ms 10588 KB Output is correct
17 Correct 47 ms 10800 KB Output is correct
18 Correct 54 ms 12632 KB Output is correct
19 Correct 55 ms 12400 KB Output is correct
20 Correct 50 ms 11088 KB Output is correct
21 Incorrect 87 ms 12636 KB Output isn't correct
22 Halted 0 ms 0 KB -