Submission #588004

# Submission time Handle Problem Language Result Execution time Memory
588004 2022-07-02T16:02:44 Z sofapuden Feast (NOI19_feast) C++14
4 / 100
935 ms 26844 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<<42), 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(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 811 ms 23136 KB Output is correct
2 Correct 836 ms 26416 KB Output is correct
3 Correct 865 ms 26844 KB Output is correct
4 Correct 858 ms 26588 KB Output is correct
5 Correct 848 ms 26380 KB Output is correct
6 Correct 861 ms 26144 KB Output is correct
7 Correct 862 ms 25992 KB Output is correct
8 Correct 841 ms 26524 KB Output is correct
9 Correct 833 ms 26120 KB Output is correct
10 Correct 849 ms 26468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 841 ms 23384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 935 ms 23688 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 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 811 ms 23136 KB Output is correct
2 Correct 836 ms 26416 KB Output is correct
3 Correct 865 ms 26844 KB Output is correct
4 Correct 858 ms 26588 KB Output is correct
5 Correct 848 ms 26380 KB Output is correct
6 Correct 861 ms 26144 KB Output is correct
7 Correct 862 ms 25992 KB Output is correct
8 Correct 841 ms 26524 KB Output is correct
9 Correct 833 ms 26120 KB Output is correct
10 Correct 849 ms 26468 KB Output is correct
11 Incorrect 841 ms 23384 KB Output isn't correct
12 Halted 0 ms 0 KB -