Submission #1070825

# Submission time Handle Problem Language Result Execution time Memory
1070825 2024-08-22T19:11:57 Z TAhmed33 Feast (NOI19_feast) C++
18 / 100
105 ms 15188 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 25;
ll a[MAXN], n, k;
pair <ll, ll> eval (ll mid) {
	pair <ll, ll> dp[n + 1][2];
	dp[1][0] = {0, 0};
	dp[1][1] = {a[1] - mid, 1};
	for (int i = 2; i <= n; i++) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		pair <ll, ll> g = {dp[i - 1][0].first + a[i] - mid, dp[i - 1][0].second + 1};
		pair <ll, ll> h = {dp[i - 1][1].first + a[i], dp[i - 1][1].second};
		dp[i][1] = max(g, h);
	}
	return max(dp[n][0], dp[n][1]);
}
void solve () {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll l = 0, r = 1e18, ans = -1;
	while (l <= r) {
		ll mid = (l + r) / 2;	
		if (eval(mid).second >= k) {
			l = mid + 1; ans = mid; 
		} else {
			r = mid - 1;
		}
	}
	cout << eval(ans).first + ans * k << '\n';
}		
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 14436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 12916 KB Output is correct
2 Correct 63 ms 13176 KB Output is correct
3 Correct 61 ms 12988 KB Output is correct
4 Incorrect 61 ms 13104 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 14936 KB Output is correct
2 Correct 94 ms 14672 KB Output is correct
3 Correct 96 ms 14932 KB Output is correct
4 Correct 95 ms 14672 KB Output is correct
5 Correct 98 ms 14940 KB Output is correct
6 Correct 100 ms 15116 KB Output is correct
7 Correct 105 ms 14940 KB Output is correct
8 Correct 95 ms 14960 KB Output is correct
9 Correct 96 ms 15188 KB Output is correct
10 Correct 104 ms 14928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 14436 KB Output isn't correct
2 Halted 0 ms 0 KB -