Submission #829940

# Submission time Handle Problem Language Result Execution time Memory
829940 2023-08-18T16:02:45 Z NK_ Feast (NOI19_feast) C++17
100 / 100
597 ms 4436 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 db EPS = 1e-3;
const ll INFL = ll(1e15);

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(INFL), 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;
	while(lo + EPS < hi) {
		db mid = (lo + hi) / 2;
		if (check(mid)) lo = mid;
		else hi = mid;
	}

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 467 ms 1364 KB Output is correct
2 Correct 478 ms 4308 KB Output is correct
3 Correct 497 ms 4296 KB Output is correct
4 Correct 490 ms 4292 KB Output is correct
5 Correct 481 ms 4300 KB Output is correct
6 Correct 472 ms 4148 KB Output is correct
7 Correct 468 ms 4180 KB Output is correct
8 Correct 484 ms 4280 KB Output is correct
9 Correct 471 ms 4272 KB Output is correct
10 Correct 485 ms 4284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 1364 KB Output is correct
2 Correct 477 ms 2644 KB Output is correct
3 Correct 471 ms 2516 KB Output is correct
4 Correct 473 ms 2516 KB Output is correct
5 Correct 477 ms 4172 KB Output is correct
6 Correct 467 ms 2488 KB Output is correct
7 Correct 479 ms 2512 KB Output is correct
8 Correct 501 ms 4300 KB Output is correct
9 Correct 470 ms 4172 KB Output is correct
10 Correct 482 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 1364 KB Output is correct
2 Correct 514 ms 4396 KB Output is correct
3 Correct 539 ms 4428 KB Output is correct
4 Correct 519 ms 4428 KB Output is correct
5 Correct 536 ms 4416 KB Output is correct
6 Correct 527 ms 4436 KB Output is correct
7 Correct 540 ms 4420 KB Output is correct
8 Correct 514 ms 4428 KB Output is correct
9 Correct 528 ms 4436 KB Output is correct
10 Correct 525 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 328 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 4 ms 352 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 467 ms 1364 KB Output is correct
2 Correct 478 ms 4308 KB Output is correct
3 Correct 497 ms 4296 KB Output is correct
4 Correct 490 ms 4292 KB Output is correct
5 Correct 481 ms 4300 KB Output is correct
6 Correct 472 ms 4148 KB Output is correct
7 Correct 468 ms 4180 KB Output is correct
8 Correct 484 ms 4280 KB Output is correct
9 Correct 471 ms 4272 KB Output is correct
10 Correct 485 ms 4284 KB Output is correct
11 Correct 466 ms 1364 KB Output is correct
12 Correct 477 ms 2644 KB Output is correct
13 Correct 471 ms 2516 KB Output is correct
14 Correct 473 ms 2516 KB Output is correct
15 Correct 477 ms 4172 KB Output is correct
16 Correct 467 ms 2488 KB Output is correct
17 Correct 479 ms 2512 KB Output is correct
18 Correct 501 ms 4300 KB Output is correct
19 Correct 470 ms 4172 KB Output is correct
20 Correct 482 ms 2508 KB Output is correct
21 Correct 519 ms 1364 KB Output is correct
22 Correct 514 ms 4396 KB Output is correct
23 Correct 539 ms 4428 KB Output is correct
24 Correct 519 ms 4428 KB Output is correct
25 Correct 536 ms 4416 KB Output is correct
26 Correct 527 ms 4436 KB Output is correct
27 Correct 540 ms 4420 KB Output is correct
28 Correct 514 ms 4428 KB Output is correct
29 Correct 528 ms 4436 KB Output is correct
30 Correct 525 ms 4432 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 320 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 316 KB Output is correct
50 Correct 1 ms 316 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 4 ms 340 KB Output is correct
53 Correct 5 ms 468 KB Output is correct
54 Correct 4 ms 340 KB Output is correct
55 Correct 4 ms 328 KB Output is correct
56 Correct 4 ms 340 KB Output is correct
57 Correct 4 ms 340 KB Output is correct
58 Correct 4 ms 340 KB Output is correct
59 Correct 4 ms 352 KB Output is correct
60 Correct 6 ms 344 KB Output is correct
61 Correct 566 ms 4396 KB Output is correct
62 Correct 578 ms 4424 KB Output is correct
63 Correct 535 ms 4436 KB Output is correct
64 Correct 583 ms 4404 KB Output is correct
65 Correct 597 ms 4420 KB Output is correct
66 Correct 586 ms 4404 KB Output is correct
67 Correct 584 ms 4428 KB Output is correct
68 Correct 528 ms 4436 KB Output is correct
69 Correct 511 ms 4428 KB Output is correct
70 Correct 510 ms 4396 KB Output is correct