Submission #991310

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

int x, k;
int arr[300005];
std::pair<int64_t,int> dp[300005][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;
				r = m-1;
			}
			else {
				l = m+1;
			}
		}
		return ret;
	};

	int64_t ret = bs();
	std::cout << sol(ret).first + ret*sol(ret).second << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 62 ms 10844 KB Output is correct
2 Correct 49 ms 10952 KB Output is correct
3 Correct 49 ms 10844 KB Output is correct
4 Correct 49 ms 10840 KB Output is correct
5 Correct 48 ms 10844 KB Output is correct
6 Correct 48 ms 10960 KB Output is correct
7 Correct 53 ms 10964 KB Output is correct
8 Correct 47 ms 10844 KB Output is correct
9 Correct 48 ms 10968 KB Output is correct
10 Correct 53 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 10840 KB Output is correct
2 Correct 43 ms 10844 KB Output is correct
3 Correct 42 ms 10972 KB Output is correct
4 Correct 49 ms 11100 KB Output is correct
5 Correct 48 ms 10844 KB Output is correct
6 Correct 41 ms 10844 KB Output is correct
7 Correct 42 ms 11008 KB Output is correct
8 Correct 50 ms 10844 KB Output is correct
9 Correct 48 ms 10844 KB Output is correct
10 Correct 42 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 10832 KB Output is correct
2 Correct 77 ms 10756 KB Output is correct
3 Correct 75 ms 10832 KB Output is correct
4 Correct 76 ms 10980 KB Output is correct
5 Correct 93 ms 10972 KB Output is correct
6 Correct 77 ms 10996 KB Output is correct
7 Correct 77 ms 10844 KB Output is correct
8 Correct 75 ms 10840 KB Output is correct
9 Correct 77 ms 10836 KB Output is correct
10 Correct 80 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 10844 KB Output is correct
2 Correct 49 ms 10952 KB Output is correct
3 Correct 49 ms 10844 KB Output is correct
4 Correct 49 ms 10840 KB Output is correct
5 Correct 48 ms 10844 KB Output is correct
6 Correct 48 ms 10960 KB Output is correct
7 Correct 53 ms 10964 KB Output is correct
8 Correct 47 ms 10844 KB Output is correct
9 Correct 48 ms 10968 KB Output is correct
10 Correct 53 ms 10844 KB Output is correct
11 Correct 43 ms 10840 KB Output is correct
12 Correct 43 ms 10844 KB Output is correct
13 Correct 42 ms 10972 KB Output is correct
14 Correct 49 ms 11100 KB Output is correct
15 Correct 48 ms 10844 KB Output is correct
16 Correct 41 ms 10844 KB Output is correct
17 Correct 42 ms 11008 KB Output is correct
18 Correct 50 ms 10844 KB Output is correct
19 Correct 48 ms 10844 KB Output is correct
20 Correct 42 ms 10844 KB Output is correct
21 Correct 77 ms 10832 KB Output is correct
22 Correct 77 ms 10756 KB Output is correct
23 Correct 75 ms 10832 KB Output is correct
24 Correct 76 ms 10980 KB Output is correct
25 Correct 93 ms 10972 KB Output is correct
26 Correct 77 ms 10996 KB Output is correct
27 Correct 77 ms 10844 KB Output is correct
28 Correct 75 ms 10840 KB Output is correct
29 Correct 77 ms 10836 KB Output is correct
30 Correct 80 ms 10844 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 108 ms 10972 KB Output is correct
62 Correct 106 ms 10844 KB Output is correct
63 Correct 94 ms 13916 KB Output is correct
64 Correct 112 ms 13880 KB Output is correct
65 Correct 118 ms 13916 KB Output is correct
66 Correct 114 ms 13912 KB Output is correct
67 Correct 118 ms 14164 KB Output is correct
68 Correct 79 ms 14008 KB Output is correct
69 Correct 77 ms 13888 KB Output is correct
70 Correct 79 ms 13932 KB Output is correct