Submission #817421

# Submission time Handle Problem Language Result Execution time Memory
817421 2023-08-09T12:23:49 Z vjudge1 Feast (NOI19_feast) C++17
40 / 100
247 ms 14648 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

#define int long long

using ii = pair<int, int>;

int n, k;
vector<int> v, pfx;

ii better(ii a, ii b){
	if (a.first != b.first){
		return (a.first > b.first) ? a : b;
	}
	return (a.second < b.second) ? a : b;
}

ii f(int lambda){
	vector<ii> dp_closed(n), dp_open(n);
	dp_closed[0] = {0, 0};
	dp_open[0] = {max(0LL, -pfx[0]), 0};

	for (int i = 1; i < n; i++){
		dp_closed[i] = better(dp_closed[i-1],
			{dp_open[i-1].first + pfx[i] - lambda, dp_open[i-1].second + 1});
		dp_open[i] = better(dp_open[i-1],
			{dp_closed[i-1].first - pfx[i], dp_closed[i-1].second});
	}

	return dp_closed[n-1];
}

void main_program(){
	cin >> n >> k;

	v.resize(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	pfx = v;
	for (int i = 1; i < n; i++) pfx[i] += pfx[i-1];

	int l = 0, r = 3e14;
	int final = -1e18;
	while (l <= r){
		int mid = (l + r) >> 1;
		auto res = f(mid);
		if (res.second <= k){
			r = mid - 1;
			final = max(final, res.first + mid * res.second);
		}
		else l = mid + 1;
	}

	cout << final << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 196 ms 14072 KB Output is correct
2 Correct 202 ms 14392 KB Output is correct
3 Correct 223 ms 14516 KB Output is correct
4 Correct 206 ms 14384 KB Output is correct
5 Correct 205 ms 14352 KB Output is correct
6 Correct 204 ms 14100 KB Output is correct
7 Correct 198 ms 14052 KB Output is correct
8 Correct 209 ms 14456 KB Output is correct
9 Correct 211 ms 14200 KB Output is correct
10 Correct 224 ms 14276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 14232 KB Output is correct
2 Correct 211 ms 14648 KB Output is correct
3 Correct 205 ms 14176 KB Output is correct
4 Correct 197 ms 14272 KB Output is correct
5 Correct 212 ms 14232 KB Output is correct
6 Correct 194 ms 14176 KB Output is correct
7 Correct 199 ms 14540 KB Output is correct
8 Correct 211 ms 14444 KB Output is correct
9 Correct 198 ms 14036 KB Output is correct
10 Correct 226 ms 14436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 14360 KB Output is correct
2 Correct 211 ms 14224 KB Output is correct
3 Correct 247 ms 14316 KB Output is correct
4 Correct 215 ms 14296 KB Output is correct
5 Correct 207 ms 14396 KB Output is correct
6 Correct 230 ms 14444 KB Output is correct
7 Correct 218 ms 14532 KB Output is correct
8 Correct 223 ms 14400 KB Output is correct
9 Correct 209 ms 14528 KB Output is correct
10 Correct 219 ms 14504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 196 ms 14072 KB Output is correct
2 Correct 202 ms 14392 KB Output is correct
3 Correct 223 ms 14516 KB Output is correct
4 Correct 206 ms 14384 KB Output is correct
5 Correct 205 ms 14352 KB Output is correct
6 Correct 204 ms 14100 KB Output is correct
7 Correct 198 ms 14052 KB Output is correct
8 Correct 209 ms 14456 KB Output is correct
9 Correct 211 ms 14200 KB Output is correct
10 Correct 224 ms 14276 KB Output is correct
11 Correct 205 ms 14232 KB Output is correct
12 Correct 211 ms 14648 KB Output is correct
13 Correct 205 ms 14176 KB Output is correct
14 Correct 197 ms 14272 KB Output is correct
15 Correct 212 ms 14232 KB Output is correct
16 Correct 194 ms 14176 KB Output is correct
17 Correct 199 ms 14540 KB Output is correct
18 Correct 211 ms 14444 KB Output is correct
19 Correct 198 ms 14036 KB Output is correct
20 Correct 226 ms 14436 KB Output is correct
21 Correct 217 ms 14360 KB Output is correct
22 Correct 211 ms 14224 KB Output is correct
23 Correct 247 ms 14316 KB Output is correct
24 Correct 215 ms 14296 KB Output is correct
25 Correct 207 ms 14396 KB Output is correct
26 Correct 230 ms 14444 KB Output is correct
27 Correct 218 ms 14532 KB Output is correct
28 Correct 223 ms 14400 KB Output is correct
29 Correct 209 ms 14528 KB Output is correct
30 Correct 219 ms 14504 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Incorrect 0 ms 212 KB Output isn't correct
42 Halted 0 ms 0 KB -