Submission #829932

# Submission time Handle Problem Language Result Execution time Memory
829932 2023-08-18T15:59:49 Z NK_ Feast (NOI19_feast) C++17
0 / 100
549 ms 4412 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;
 
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;

const int INF = 1e9 + 10;
const int LG = 70;
const db EPS = 1e-3;
const ll INFL = ll(1e16);

using T = pair<db, int>;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K; cin >> N >> K;
	vi A(N); for(auto& x : A) cin >> x;

	V<T> dp(2); 
	auto check = [&](db lambda) {
		dp[0] = {0, 0}; dp[1] = {-db(INF), 0};
		for(int i = 0; i < N; i++) {
			V<T> ndp(2); ndp[0] = max(dp[0], dp[1]);
			ndp[1] = max(
				mp(dp[0].f + A[i] - lambda, dp[0].s + 1), 
				mp(dp[1].f + A[i], dp[1].s)
			);
			dp.swap(ndp);
		} 
		return max(dp[0], dp[1]).s >= K;
	};

	db lo = 0, hi = INFL;
	for(int t = 0; t < LG; t++) {
		db mid = (lo + hi) / 2;
		if (lo + EPS > hi) break;
		if (check(mid)) lo = mid;
		else hi = mid;
	}

	check(lo);/* cout << lo << endl;*/
	cout << round(lo * db(K) + max(dp[0], dp[1]).f) << nl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 504 ms 4172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 515 ms 2480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 549 ms 4412 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 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 504 ms 4172 KB Output isn't correct
2 Halted 0 ms 0 KB -