Submission #545010

# Submission time Handle Problem Language Result Execution time Memory
545010 2022-04-03T10:12:07 Z pure_mem Feast (NOI19_feast) C++14
100 / 100
705 ms 24588 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define X first
#define Y second
#define MP make_pair

using namespace std;

const int N = 3e5 + 12;

int n, k; 
ll a[N];
pair<ld, int> dp[N][2];

void prints(pair<ld, int> x) {
	cerr << x.X << " " << x.Y;
}

pair<ld, int> get(ld m, bool debug = 0) {
	dp[1][0] = {0, 0};
	dp[1][1] = {a[1] - m, 1};
	for(int i = 2;i <= n;i++) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][1] = max(MP(dp[i - 1][0].X + a[i] - m, dp[i - 1][0].Y + 1), 
					   MP(dp[i - 1][1].X + a[i], dp[i - 1][1].Y));	
		if(debug) {
			prints(dp[i][0]), cerr << " | ", prints(dp[i][1]);
			cerr << "\n";
		}
	}	
	return max(dp[n][0], dp[n][1]);
}

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 	
	cin >> n >> k;
	for(int i = 1;i <= n;i++)
		cin >> a[i];

	ld l = 0, r = 1e15;
	for(int it = 0;it < 100;it++) {
		ld m = (l + r) / 2;
		auto mid = get(m);
		if(mid.Y >= k) {
			l = m;
		} 	
		else {
			r = m;
		}
		
	}
	
	auto mid = get(l);      
	ll answer = round(mid.X + l * k);
	cout << answer;
}
# Verdict Execution time Memory Grader output
1 Correct 351 ms 23540 KB Output is correct
2 Correct 352 ms 23924 KB Output is correct
3 Correct 392 ms 24300 KB Output is correct
4 Correct 349 ms 24140 KB Output is correct
5 Correct 400 ms 24008 KB Output is correct
6 Correct 366 ms 23608 KB Output is correct
7 Correct 367 ms 23600 KB Output is correct
8 Correct 380 ms 24080 KB Output is correct
9 Correct 365 ms 23656 KB Output is correct
10 Correct 349 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 363 ms 22048 KB Output is correct
2 Correct 365 ms 22544 KB Output is correct
3 Correct 385 ms 22040 KB Output is correct
4 Correct 350 ms 22212 KB Output is correct
5 Correct 373 ms 23616 KB Output is correct
6 Correct 386 ms 21996 KB Output is correct
7 Correct 388 ms 22580 KB Output is correct
8 Correct 371 ms 24176 KB Output is correct
9 Correct 375 ms 23548 KB Output is correct
10 Correct 335 ms 22424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 24240 KB Output is correct
2 Correct 445 ms 23928 KB Output is correct
3 Correct 446 ms 24088 KB Output is correct
4 Correct 494 ms 23928 KB Output is correct
5 Correct 444 ms 24156 KB Output is correct
6 Correct 441 ms 24296 KB Output is correct
7 Correct 459 ms 24288 KB Output is correct
8 Correct 452 ms 24140 KB Output is correct
9 Correct 459 ms 24392 KB Output is correct
10 Correct 465 ms 24396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 464 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 5 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 464 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 5 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 23540 KB Output is correct
2 Correct 352 ms 23924 KB Output is correct
3 Correct 392 ms 24300 KB Output is correct
4 Correct 349 ms 24140 KB Output is correct
5 Correct 400 ms 24008 KB Output is correct
6 Correct 366 ms 23608 KB Output is correct
7 Correct 367 ms 23600 KB Output is correct
8 Correct 380 ms 24080 KB Output is correct
9 Correct 365 ms 23656 KB Output is correct
10 Correct 349 ms 23900 KB Output is correct
11 Correct 363 ms 22048 KB Output is correct
12 Correct 365 ms 22544 KB Output is correct
13 Correct 385 ms 22040 KB Output is correct
14 Correct 350 ms 22212 KB Output is correct
15 Correct 373 ms 23616 KB Output is correct
16 Correct 386 ms 21996 KB Output is correct
17 Correct 388 ms 22580 KB Output is correct
18 Correct 371 ms 24176 KB Output is correct
19 Correct 375 ms 23548 KB Output is correct
20 Correct 335 ms 22424 KB Output is correct
21 Correct 460 ms 24240 KB Output is correct
22 Correct 445 ms 23928 KB Output is correct
23 Correct 446 ms 24088 KB Output is correct
24 Correct 494 ms 23928 KB Output is correct
25 Correct 444 ms 24156 KB Output is correct
26 Correct 441 ms 24296 KB Output is correct
27 Correct 459 ms 24288 KB Output is correct
28 Correct 452 ms 24140 KB Output is correct
29 Correct 459 ms 24392 KB Output is correct
30 Correct 465 ms 24396 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 328 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 324 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 4 ms 468 KB Output is correct
52 Correct 4 ms 464 KB Output is correct
53 Correct 4 ms 468 KB Output is correct
54 Correct 5 ms 468 KB Output is correct
55 Correct 5 ms 468 KB Output is correct
56 Correct 4 ms 464 KB Output is correct
57 Correct 4 ms 468 KB Output is correct
58 Correct 5 ms 468 KB Output is correct
59 Correct 4 ms 468 KB Output is correct
60 Correct 4 ms 468 KB Output is correct
61 Correct 637 ms 23900 KB Output is correct
62 Correct 624 ms 24588 KB Output is correct
63 Correct 563 ms 23828 KB Output is correct
64 Correct 690 ms 24208 KB Output is correct
65 Correct 688 ms 24288 KB Output is correct
66 Correct 705 ms 24236 KB Output is correct
67 Correct 671 ms 23860 KB Output is correct
68 Correct 497 ms 24324 KB Output is correct
69 Correct 480 ms 23844 KB Output is correct
70 Correct 489 ms 23740 KB Output is correct