답안 #440325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440325 2021-07-02T05:13:29 Z dongliu0426 Feast (NOI19_feast) C++14
100 / 100
711 ms 23320 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 300000;
const long long INF = (long long) 300000 * 1000000000;

int n, k, a[N + 1];
pair<long double, int> dp[N + 1][2];
	
bool check(long double penalty) {
	dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0};
	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][1].first + a[i], dp[i - 1][1].second),
			make_pair(dp[i - 1][0].first + a[i] - penalty, dp[i - 1][0].second + 1));
	}
	return max(dp[n][0], dp[n][1]).second >= k;
};

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	long double lower = 0, upper = INF;
	for (int it = 0; it < 100; ++it) {
		long double mid = (lower + upper) / 2;
		if (check(mid)) {
			lower = mid;
		} else {
			upper = mid;
		}
	}
	long double penalty = lower;
	check(penalty);
	printf("%lld\n", (long long) round(penalty * k + max(dp[n][0], dp[n][1]).first));
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d", a + i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 22416 KB Output is correct
2 Correct 487 ms 22836 KB Output is correct
3 Correct 482 ms 23016 KB Output is correct
4 Correct 455 ms 22852 KB Output is correct
5 Correct 474 ms 22812 KB Output is correct
6 Correct 443 ms 22344 KB Output is correct
7 Correct 447 ms 22344 KB Output is correct
8 Correct 470 ms 23000 KB Output is correct
9 Correct 466 ms 22424 KB Output is correct
10 Correct 474 ms 22596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 20872 KB Output is correct
2 Correct 454 ms 21220 KB Output is correct
3 Correct 467 ms 20760 KB Output is correct
4 Correct 455 ms 21028 KB Output is correct
5 Correct 459 ms 22448 KB Output is correct
6 Correct 442 ms 20932 KB Output is correct
7 Correct 483 ms 21372 KB Output is correct
8 Correct 485 ms 22972 KB Output is correct
9 Correct 457 ms 22312 KB Output is correct
10 Correct 462 ms 21284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 534 ms 22968 KB Output is correct
2 Correct 528 ms 22740 KB Output is correct
3 Correct 545 ms 23048 KB Output is correct
4 Correct 536 ms 22852 KB Output is correct
5 Correct 515 ms 22852 KB Output is correct
6 Correct 533 ms 23100 KB Output is correct
7 Correct 536 ms 23188 KB Output is correct
8 Correct 523 ms 23000 KB Output is correct
9 Correct 533 ms 23320 KB Output is correct
10 Correct 525 ms 23192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 5 ms 332 KB Output is correct
23 Correct 5 ms 332 KB Output is correct
24 Correct 5 ms 440 KB Output is correct
25 Correct 4 ms 464 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 6 ms 464 KB Output is correct
28 Correct 4 ms 444 KB Output is correct
29 Correct 6 ms 460 KB Output is correct
30 Correct 5 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 22416 KB Output is correct
2 Correct 487 ms 22836 KB Output is correct
3 Correct 482 ms 23016 KB Output is correct
4 Correct 455 ms 22852 KB Output is correct
5 Correct 474 ms 22812 KB Output is correct
6 Correct 443 ms 22344 KB Output is correct
7 Correct 447 ms 22344 KB Output is correct
8 Correct 470 ms 23000 KB Output is correct
9 Correct 466 ms 22424 KB Output is correct
10 Correct 474 ms 22596 KB Output is correct
11 Correct 446 ms 20872 KB Output is correct
12 Correct 454 ms 21220 KB Output is correct
13 Correct 467 ms 20760 KB Output is correct
14 Correct 455 ms 21028 KB Output is correct
15 Correct 459 ms 22448 KB Output is correct
16 Correct 442 ms 20932 KB Output is correct
17 Correct 483 ms 21372 KB Output is correct
18 Correct 485 ms 22972 KB Output is correct
19 Correct 457 ms 22312 KB Output is correct
20 Correct 462 ms 21284 KB Output is correct
21 Correct 534 ms 22968 KB Output is correct
22 Correct 528 ms 22740 KB Output is correct
23 Correct 545 ms 23048 KB Output is correct
24 Correct 536 ms 22852 KB Output is correct
25 Correct 515 ms 22852 KB Output is correct
26 Correct 533 ms 23100 KB Output is correct
27 Correct 536 ms 23188 KB Output is correct
28 Correct 523 ms 23000 KB Output is correct
29 Correct 533 ms 23320 KB Output is correct
30 Correct 525 ms 23192 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 2 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 4 ms 460 KB Output is correct
52 Correct 5 ms 332 KB Output is correct
53 Correct 5 ms 332 KB Output is correct
54 Correct 5 ms 440 KB Output is correct
55 Correct 4 ms 464 KB Output is correct
56 Correct 4 ms 460 KB Output is correct
57 Correct 6 ms 464 KB Output is correct
58 Correct 4 ms 444 KB Output is correct
59 Correct 6 ms 460 KB Output is correct
60 Correct 5 ms 448 KB Output is correct
61 Correct 691 ms 22596 KB Output is correct
62 Correct 678 ms 23312 KB Output is correct
63 Correct 578 ms 22648 KB Output is correct
64 Correct 711 ms 23176 KB Output is correct
65 Correct 703 ms 23104 KB Output is correct
66 Correct 686 ms 23144 KB Output is correct
67 Correct 698 ms 22600 KB Output is correct
68 Correct 531 ms 23124 KB Output is correct
69 Correct 538 ms 22672 KB Output is correct
70 Correct 506 ms 22468 KB Output is correct