Submission #587994

# Submission time Handle Problem Language Result Execution time Memory
587994 2022-07-02T15:55:14 Z sofapuden Feast (NOI19_feast) C++14
0 / 100
1000 ms 26756 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<<60), bes = 0;
	while(l<=r){
		ll m = (l+r)>>1;
		vector<vector<pair<ll,ll>>> dp(n,vector<pair<ll,ll>>(2));
		dp[0][0] = {0,0};
		dp[0][1] = {-m+v[0],0};
		for(int i = 1; i < n; ++i){
			dp[i][0] = max(dp[i-1][0],{dp[i-1][1].first,dp[i-1][1].second+1});
			dp[i][1] = max(dp[i-1][1],{dp[i-1][0].first-m,dp[i-1][0].second});
			dp[i][1].first+=v[i];
		}
		pair<ll,ll> b = max(dp[n-1][0], dp[n-1][1]);
		if(b.second >= m){
			bes = b.first + m*k;
			l = m+1;
		}
		else{
			r = m-1;
		}
	}
	cout << bes << '\n';
}

int main(){
	solve();
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 25900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 24496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 26756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 25900 KB Time limit exceeded
2 Halted 0 ms 0 KB -