Submission #991307

# Submission time Handle Problem Language Result Execution time Memory
991307 2024-06-01T21:23:30 Z xnqs Feast (NOI19_feast) C++17
0 / 100
9 ms 1372 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>

int x, k;
int arr[100005];
std::pair<int64_t,int> dp[100005][2];

std::pair<int64_t,int> sol(int64_t lambda) {
	dp[0][0] = {0,0};
	dp[0][1] = {arr[0]-lambda,1};
	for (int i = 1; i < x; i++) {
		dp[i][0] = std::max(dp[i-1][0],dp[i-1][1]);
		dp[i][1] = std::max(std::pair<int64_t,int>(dp[i-1][0].first+arr[i]-lambda,dp[i-1][0].second+1),std::pair<int64_t,int>(dp[i-1][1].first+arr[i],dp[i-1][1].second));
	}
	return std::max(dp[x-1][0],dp[x-1][1]);
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	std::cin >> x >> k;
	for (int i = 0; i < x; i++) {
		std::cin >> arr[i];
	}

	const auto bs = [&]() {
		int64_t l = 0, r = 1000000000000000000;
		int64_t ret = 69420;
		while (l<=r) {
			int64_t m = (l+r)>>1;
			if (sol(m).second>=k) {
				ret = m;
				l = m+1;
			}
			else {
				r = m-1;
			}
		}
		return ret;
	};

	int64_t ret = bs();
	std::cout << sol(ret).first + ret*k << "\n";
}
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 1372 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 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 348 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 Runtime error 7 ms 1368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -