Submission #1017565

# Submission time Handle Problem Language Result Execution time Memory
1017565 2024-07-09T08:53:48 Z vjudge1 Feast (NOI19_feast) C++17
12 / 100
83 ms 12368 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define mp make_pair
using namespace std;

const int N = 3e5+1;

int n, k;
ll a[N];

pair<ll, int> dp[N][2];
pair<ll, int> solve(ll lambda) {
	dp[0][1] = {-lambda,1};
	dp[0][0] = {0,0};
	for (int i = 1; i <= n; i++) {
		dp[i][1] = max(
			mp(dp[i-1][1].first+a[i], dp[i-1][1].second),
			mp(dp[i-1][0].first+a[i]-lambda, dp[i-1][0].second+1)
		);
		dp[i][0] = max(dp[i-1][0], dp[i-1][1]);	
	}
	return max(dp[n][0], dp[n][1]);
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; cin >> a[i++]);
	ll l = 1, r = 1e9;
	while (l < r) {
		const ll mid = (l+r)/2;
		if (solve(mid).second > k)
			l = mid+1;
		else
			r = mid;
	}
	cout << solve(l).first + l*solve(l).second;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 12124 KB Output is correct
2 Correct 37 ms 12124 KB Output is correct
3 Correct 39 ms 12116 KB Output is correct
4 Correct 38 ms 12120 KB Output is correct
5 Correct 38 ms 12112 KB Output is correct
6 Correct 38 ms 12064 KB Output is correct
7 Correct 38 ms 12108 KB Output is correct
8 Correct 38 ms 12124 KB Output is correct
9 Correct 43 ms 12108 KB Output is correct
10 Correct 38 ms 12368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 12120 KB Output is correct
2 Correct 33 ms 12120 KB Output is correct
3 Correct 32 ms 12124 KB Output is correct
4 Correct 31 ms 12124 KB Output is correct
5 Correct 41 ms 11864 KB Output is correct
6 Correct 33 ms 12120 KB Output is correct
7 Correct 32 ms 12124 KB Output is correct
8 Correct 48 ms 12120 KB Output is correct
9 Correct 39 ms 11860 KB Output is correct
10 Correct 32 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 12152 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 38 ms 12124 KB Output is correct
2 Correct 37 ms 12124 KB Output is correct
3 Correct 39 ms 12116 KB Output is correct
4 Correct 38 ms 12120 KB Output is correct
5 Correct 38 ms 12112 KB Output is correct
6 Correct 38 ms 12064 KB Output is correct
7 Correct 38 ms 12108 KB Output is correct
8 Correct 38 ms 12124 KB Output is correct
9 Correct 43 ms 12108 KB Output is correct
10 Correct 38 ms 12368 KB Output is correct
11 Correct 34 ms 12120 KB Output is correct
12 Correct 33 ms 12120 KB Output is correct
13 Correct 32 ms 12124 KB Output is correct
14 Correct 31 ms 12124 KB Output is correct
15 Correct 41 ms 11864 KB Output is correct
16 Correct 33 ms 12120 KB Output is correct
17 Correct 32 ms 12124 KB Output is correct
18 Correct 48 ms 12120 KB Output is correct
19 Correct 39 ms 11860 KB Output is correct
20 Correct 32 ms 12116 KB Output is correct
21 Incorrect 83 ms 12152 KB Output isn't correct
22 Halted 0 ms 0 KB -