Submission #954855

# Submission time Handle Problem Language Result Execution time Memory
954855 2024-03-28T18:01:09 Z mat_jur Feast (NOI19_feast) C++17
100 / 100
220 ms 16068 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else 
#define cerr if(0)cout
#define debug(X) ;
#endif
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define ssize(x) int(x.size())
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int &x : a) cin >> x;

	auto solve_lambda = [&](ll lambda) {
		vector<pair<ll, int>> dp[2];
		dp[0].resize(n);
		dp[1].resize(n);

		dp[0][0] = mp(0LL, 0);
		dp[1][0] = mp(a[0] - lambda, 1);
		for(int i = 1; i < n; ++i) {
			dp[0][i] = max(dp[0][i-1], dp[1][i-1]);
			dp[1][i] = max(mp(dp[1][i-1].fi + a[i], dp[1][i-1].se), mp(dp[0][i-1].fi + a[i] - lambda, dp[0][i-1].se + 1));
		}
		return max(dp[0][n-1], dp[1][n-1]);
	};

	ll low = 0, high = 1e15;
	while (high - low > 1) {
		ll mid = (high + low) / 2;
		if(solve_lambda(mid).se >= k) low = mid;
		else high = mid;
	}

	debug(low);
	auto [u, c] = solve_lambda(low);
	debug(u);
	debug(c);
	cout << u + k * low << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 158 ms 13508 KB Output is correct
2 Correct 141 ms 13804 KB Output is correct
3 Correct 165 ms 13976 KB Output is correct
4 Correct 167 ms 14340 KB Output is correct
5 Correct 140 ms 13800 KB Output is correct
6 Correct 135 ms 13572 KB Output is correct
7 Correct 153 ms 13528 KB Output is correct
8 Correct 139 ms 13920 KB Output is correct
9 Correct 153 ms 15656 KB Output is correct
10 Correct 155 ms 15760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 11976 KB Output is correct
2 Correct 135 ms 12232 KB Output is correct
3 Correct 147 ms 11944 KB Output is correct
4 Correct 156 ms 12376 KB Output is correct
5 Correct 134 ms 13632 KB Output is correct
6 Correct 153 ms 11944 KB Output is correct
7 Correct 150 ms 12268 KB Output is correct
8 Correct 166 ms 13972 KB Output is correct
9 Correct 155 ms 13576 KB Output is correct
10 Correct 152 ms 12176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 14100 KB Output is correct
2 Correct 180 ms 15748 KB Output is correct
3 Correct 163 ms 13960 KB Output is correct
4 Correct 154 ms 13884 KB Output is correct
5 Correct 160 ms 13996 KB Output is correct
6 Correct 176 ms 14016 KB Output is correct
7 Correct 160 ms 14084 KB Output is correct
8 Correct 171 ms 13952 KB Output is correct
9 Correct 162 ms 14152 KB Output is correct
10 Correct 176 ms 16020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 456 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 360 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 456 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 360 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 552 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 612 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 13508 KB Output is correct
2 Correct 141 ms 13804 KB Output is correct
3 Correct 165 ms 13976 KB Output is correct
4 Correct 167 ms 14340 KB Output is correct
5 Correct 140 ms 13800 KB Output is correct
6 Correct 135 ms 13572 KB Output is correct
7 Correct 153 ms 13528 KB Output is correct
8 Correct 139 ms 13920 KB Output is correct
9 Correct 153 ms 15656 KB Output is correct
10 Correct 155 ms 15760 KB Output is correct
11 Correct 151 ms 11976 KB Output is correct
12 Correct 135 ms 12232 KB Output is correct
13 Correct 147 ms 11944 KB Output is correct
14 Correct 156 ms 12376 KB Output is correct
15 Correct 134 ms 13632 KB Output is correct
16 Correct 153 ms 11944 KB Output is correct
17 Correct 150 ms 12268 KB Output is correct
18 Correct 166 ms 13972 KB Output is correct
19 Correct 155 ms 13576 KB Output is correct
20 Correct 152 ms 12176 KB Output is correct
21 Correct 166 ms 14100 KB Output is correct
22 Correct 180 ms 15748 KB Output is correct
23 Correct 163 ms 13960 KB Output is correct
24 Correct 154 ms 13884 KB Output is correct
25 Correct 160 ms 13996 KB Output is correct
26 Correct 176 ms 14016 KB Output is correct
27 Correct 160 ms 14084 KB Output is correct
28 Correct 171 ms 13952 KB Output is correct
29 Correct 162 ms 14152 KB Output is correct
30 Correct 176 ms 16020 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 456 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 360 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 1 ms 552 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 612 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 207 ms 13792 KB Output is correct
62 Correct 207 ms 16068 KB Output is correct
63 Correct 164 ms 13792 KB Output is correct
64 Correct 195 ms 14044 KB Output is correct
65 Correct 214 ms 14012 KB Output is correct
66 Correct 220 ms 14140 KB Output is correct
67 Correct 213 ms 13824 KB Output is correct
68 Correct 178 ms 14064 KB Output is correct
69 Correct 191 ms 13808 KB Output is correct
70 Correct 171 ms 13740 KB Output is correct