Submission #409522

# Submission time Handle Problem Language Result Execution time Memory
409522 2021-05-21T03:20:20 Z penguinhacker Feast (NOI19_feast) C++14
0 / 100
108 ms 7968 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=3e5;
int n, k, a[mxN], cnt[mxN];
ll dp[mxN];

int solve(ll x) {
	ll s=0;
	ar<ll, 2> cur={0, 0};
	for (int i=0; i<n; ++i) {
		s+=a[i];
		dp[i]=i?dp[i-1]:0;
		cnt[i]=i?cnt[i-1]:0;
		if (cur[0]+s-x>dp[i])
			dp[i]=cur[0]+s-x, cnt[i]=cur[1]+1;
		if (dp[i]-s>cur[0])
			cur={dp[i]-s, cnt[i]};
	}
	return cnt[n-1];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for (int i=0; i<n; ++i)
		cin >> a[i];
	ll lb=0, rb=1e15;
	while(lb<rb) {
		ll m=(lb+rb)/2;
		if (solve(m)<=k)
			rb=m;
		else
			lb=m+1;
	}
	solve(lb);
	//cout << lb << " " << dp[n-1] << " " << cnt[n-1] << "\n";
	cout << dp[n-1]+round(cnt[n-1]*lb);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 7732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 7968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 7732 KB Output isn't correct
2 Halted 0 ms 0 KB -