Submission #588003

# Submission time Handle Problem Language Result Execution time Memory
588003 2022-07-02T16:02:33 Z Temmie Feast (NOI19_feast) C++17
0 / 100
1000 ms 37108 KB
#include <bits/stdc++.h>

typedef std::pair <long long, int> pa;

int n, k;
std::vector <int> a;

pa g(int l) {
	std::vector <std::vector <pa>> dp(n, std::vector <pa> (2, { -1, -1 }));
	auto f = [&] (auto&& self, int i, bool is) -> pa {
		if (i >= n) {
			return { 0, 0 };
		}
		if (dp[i][is].first != -1) {
			return dp[i][is];
		}
		dp[i][is] = self(self, i + 1, false);
		pa cand = self(self, i + 1, true);
		cand.second += !is;
		cand.first += a[i];
		cand.first -= l * !is;
		dp[i][is] = std::max(dp[i][is], cand);
		return dp[i][is];
	};
	return f(f, 0, false);
}

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	std::cin >> n >> k;
	a.resize(n);
	for (int& x : a) {
		std::cin >> x;
	}
	long long l = 0, r = 1LL << 42, ans = 0;
	while (l <= r) {
		long long mid = (l + r) >> 1;
		pa val = g(mid);
		if (val.first >= mid) {
			l = mid + 1;
			ans = val.first + mid * k;
		} else {
			r = mid - 1;
		}
	}
	std::cout << ans << "\n";
	
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 36444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 36904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 37108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 36444 KB Time limit exceeded
2 Halted 0 ms 0 KB -