Submission #1097314

# Submission time Handle Problem Language Result Execution time Memory
1097314 2024-10-06T19:50:26 Z vjudge1 Feast (NOI19_feast) C++17
18 / 100
475 ms 47316 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);
}
// 1-> (i - 1) not taken vice verca
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], 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 = 1LL << 42, res = 0;
	while (l <= r) {
		long long m = (l + r) / 2;
		auto [x, y] = get(m);
		if (y < k) {
			r = m - 1;
		} else l = m + 1, res = x + k * m;;
	}
	cout << res << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 403 ms 46420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 425 ms 46536 KB Output is correct
2 Correct 414 ms 47316 KB Output is correct
3 Correct 409 ms 46672 KB Output is correct
4 Incorrect 404 ms 46764 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 475 ms 46956 KB Output is correct
2 Correct 442 ms 46416 KB Output is correct
3 Correct 445 ms 46884 KB Output is correct
4 Correct 450 ms 46672 KB Output is correct
5 Correct 446 ms 46884 KB Output is correct
6 Correct 442 ms 47188 KB Output is correct
7 Correct 448 ms 47216 KB Output is correct
8 Correct 461 ms 46660 KB Output is correct
9 Correct 421 ms 47184 KB Output is correct
10 Correct 430 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Incorrect 3 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Incorrect 3 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Incorrect 3 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 403 ms 46420 KB Output isn't correct
2 Halted 0 ms 0 KB -