답안 #739797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739797 2023-05-11T10:07:10 Z NeroZein Feast (NOI19_feast) C++17
100 / 100
144 ms 10920 KB
#include "bits/stdc++.h"
using namespace std;
 
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
 
const int N = 300005;
 
int n, k;
int a[N];
pair<long long,int> dp[N][2];
pair<long long,int> solve (long long cost) {
	dp[0][0] = {0LL, 0};
	dp[0][1] = {-1e15, -N};
	for (int i = 1; i <= n; ++i) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][1] = max(make_pair(dp[i - 1][0].first + a[i] - cost, dp[i - 1][0].second + 1), 
									 make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second)); 
	}
	return max(dp[n][0], dp[n][1]); 
}
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	long long l = 0, r = (long long) N * 1e9;
	while (l < r) {
		long long mid = (l + r + 1) >> 1;
		if (solve(mid).second > k) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
  	if (solve(l + 1).second == k) {
      cout << solve(l + 1).first + (l + 1) * k << '\n';
    } else {
      cout << solve(l).first + (l) * k << '\n';
    }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 10544 KB Output is correct
2 Correct 89 ms 10740 KB Output is correct
3 Correct 93 ms 10752 KB Output is correct
4 Correct 87 ms 10700 KB Output is correct
5 Correct 87 ms 10728 KB Output is correct
6 Correct 89 ms 10460 KB Output is correct
7 Correct 89 ms 10444 KB Output is correct
8 Correct 94 ms 10768 KB Output is correct
9 Correct 89 ms 10572 KB Output is correct
10 Correct 90 ms 10612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 10620 KB Output is correct
2 Correct 84 ms 10848 KB Output is correct
3 Correct 80 ms 10576 KB Output is correct
4 Correct 84 ms 10604 KB Output is correct
5 Correct 87 ms 10564 KB Output is correct
6 Correct 79 ms 10592 KB Output is correct
7 Correct 81 ms 10888 KB Output is correct
8 Correct 91 ms 10756 KB Output is correct
9 Correct 85 ms 10632 KB Output is correct
10 Correct 84 ms 10788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 10688 KB Output is correct
2 Correct 104 ms 10572 KB Output is correct
3 Correct 102 ms 10656 KB Output is correct
4 Correct 102 ms 10536 KB Output is correct
5 Correct 102 ms 10672 KB Output is correct
6 Correct 107 ms 10828 KB Output is correct
7 Correct 101 ms 10740 KB Output is correct
8 Correct 99 ms 10652 KB Output is correct
9 Correct 103 ms 10776 KB Output is correct
10 Correct 100 ms 10820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 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 340 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 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 340 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 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 10544 KB Output is correct
2 Correct 89 ms 10740 KB Output is correct
3 Correct 93 ms 10752 KB Output is correct
4 Correct 87 ms 10700 KB Output is correct
5 Correct 87 ms 10728 KB Output is correct
6 Correct 89 ms 10460 KB Output is correct
7 Correct 89 ms 10444 KB Output is correct
8 Correct 94 ms 10768 KB Output is correct
9 Correct 89 ms 10572 KB Output is correct
10 Correct 90 ms 10612 KB Output is correct
11 Correct 80 ms 10620 KB Output is correct
12 Correct 84 ms 10848 KB Output is correct
13 Correct 80 ms 10576 KB Output is correct
14 Correct 84 ms 10604 KB Output is correct
15 Correct 87 ms 10564 KB Output is correct
16 Correct 79 ms 10592 KB Output is correct
17 Correct 81 ms 10888 KB Output is correct
18 Correct 91 ms 10756 KB Output is correct
19 Correct 85 ms 10632 KB Output is correct
20 Correct 84 ms 10788 KB Output is correct
21 Correct 106 ms 10688 KB Output is correct
22 Correct 104 ms 10572 KB Output is correct
23 Correct 102 ms 10656 KB Output is correct
24 Correct 102 ms 10536 KB Output is correct
25 Correct 102 ms 10672 KB Output is correct
26 Correct 107 ms 10828 KB Output is correct
27 Correct 101 ms 10740 KB Output is correct
28 Correct 99 ms 10652 KB Output is correct
29 Correct 103 ms 10776 KB Output is correct
30 Correct 100 ms 10820 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 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 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 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 340 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 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 143 ms 10604 KB Output is correct
62 Correct 139 ms 10920 KB Output is correct
63 Correct 111 ms 10568 KB Output is correct
64 Correct 143 ms 10788 KB Output is correct
65 Correct 138 ms 10732 KB Output is correct
66 Correct 144 ms 10748 KB Output is correct
67 Correct 140 ms 10572 KB Output is correct
68 Correct 105 ms 10784 KB Output is correct
69 Correct 98 ms 10560 KB Output is correct
70 Correct 98 ms 10444 KB Output is correct