Submission #1097305

# Submission time Handle Problem Language Result Execution time Memory
1097305 2024-10-06T19:25:38 Z vjudge1 Feast (NOI19_feast) C++17
0 / 100
397 ms 49804 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int n, vis[N][2];
long long pan, a[N];
pair<long long, int> mem[N][2];
pair<long long, int> operator + (pair<long long, int> x, pair<long long, int> y) {
	return make_pair(x.first + y.first, x.second + y.second);
}
pair<long long, int> dp(int i, int f) {
	if (i == n) return {0, 0};
	if (vis[i][f]) return mem[i][f];
	vis[i][f] = 1;
	auto &ret = mem[i][f];
	ret = dp(i + 1, 1);
	ret = max(ret, dp(i + 1, 0) + make_pair(-pan * f + a[i], -1 * f));
	return ret;
}
pair<long long, int> get(long long x) {
	pan = x;
	memset(vis, 0, sizeof(vis));
	return dp(0, 1);
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	// auto z = get(1);
	// cout << z.first << endl;
	// cout << z.second << endl;
	long long l = 0, r = 1 << 30, res = 0;
	while (l <= r) {
		long long m = (l + r) / 2;
		auto [x, y] = get(m);
		if (-y == k) {
			res = x + k * m;
			r = m - 1;
		} else if (-y < k) {
			r = m - 1;
		} else l = m + 1;
	}
	cout << res << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 48724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 311 ms 47188 KB Output is correct
2 Correct 298 ms 48372 KB Output is correct
3 Correct 314 ms 47188 KB Output is correct
4 Incorrect 346 ms 47704 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 397 ms 49804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 48724 KB Output isn't correct
2 Halted 0 ms 0 KB -