답안 #1017317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017317 2024-07-09T07:22:44 Z vjudge1 Feast (NOI19_feast) C++14
100 / 100
119 ms 12368 KB
#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

void file(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	if(fopen(name".inp", "r")) {
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
}

const int maxn = 3e5 + 5;

ll n, k;
ll a[maxn];

pll dp[maxn][2];

pll ck(ll mid){
	dp[1][0] = {0, 0};
	dp[1][1] = {a[1] - mid, 1};
	for(int i = 2; i <= n; i++){
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		pll sus1 = {dp[i - 1][0].first + a[i] - mid, dp[i - 1][0].second + 1};
		pll sus2 = {dp[i - 1][1].first + a[i], dp[i - 1][1].second};
		dp[i][1] = max(sus1, sus2);
	}
	return max(dp[n][0], dp[n][1]);
}

void solve(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	ll l = 0, r = 1e18, mid;
	while(l < r){
		mid = (l + r + 1) / 2;
		if(ck(mid).second >= k){
			l = mid;
		}else{
			r = mid - 1;
		}
	}
	cout << ck(l).first + l * k;
}

int main(){
	file();
	solve();
}

Compilation message

feast.cpp: In function 'void file()':
feast.cpp:11:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 11920 KB Output is correct
2 Correct 70 ms 11992 KB Output is correct
3 Correct 54 ms 12124 KB Output is correct
4 Correct 70 ms 11996 KB Output is correct
5 Correct 52 ms 11868 KB Output is correct
6 Correct 51 ms 11820 KB Output is correct
7 Correct 61 ms 12124 KB Output is correct
8 Correct 50 ms 12112 KB Output is correct
9 Correct 68 ms 12108 KB Output is correct
10 Correct 54 ms 11972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 11864 KB Output is correct
2 Correct 59 ms 12368 KB Output is correct
3 Correct 45 ms 12120 KB Output is correct
4 Correct 70 ms 12144 KB Output is correct
5 Correct 56 ms 12036 KB Output is correct
6 Correct 56 ms 12124 KB Output is correct
7 Correct 48 ms 12120 KB Output is correct
8 Correct 56 ms 12124 KB Output is correct
9 Correct 52 ms 11608 KB Output is correct
10 Correct 53 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12116 KB Output is correct
2 Correct 83 ms 12068 KB Output is correct
3 Correct 86 ms 12124 KB Output is correct
4 Correct 81 ms 12120 KB Output is correct
5 Correct 79 ms 12112 KB Output is correct
6 Correct 81 ms 12112 KB Output is correct
7 Correct 84 ms 12112 KB Output is correct
8 Correct 77 ms 12112 KB Output is correct
9 Correct 73 ms 11988 KB Output is correct
10 Correct 78 ms 12008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 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
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 11920 KB Output is correct
2 Correct 70 ms 11992 KB Output is correct
3 Correct 54 ms 12124 KB Output is correct
4 Correct 70 ms 11996 KB Output is correct
5 Correct 52 ms 11868 KB Output is correct
6 Correct 51 ms 11820 KB Output is correct
7 Correct 61 ms 12124 KB Output is correct
8 Correct 50 ms 12112 KB Output is correct
9 Correct 68 ms 12108 KB Output is correct
10 Correct 54 ms 11972 KB Output is correct
11 Correct 47 ms 11864 KB Output is correct
12 Correct 59 ms 12368 KB Output is correct
13 Correct 45 ms 12120 KB Output is correct
14 Correct 70 ms 12144 KB Output is correct
15 Correct 56 ms 12036 KB Output is correct
16 Correct 56 ms 12124 KB Output is correct
17 Correct 48 ms 12120 KB Output is correct
18 Correct 56 ms 12124 KB Output is correct
19 Correct 52 ms 11608 KB Output is correct
20 Correct 53 ms 12124 KB Output is correct
21 Correct 79 ms 12116 KB Output is correct
22 Correct 83 ms 12068 KB Output is correct
23 Correct 86 ms 12124 KB Output is correct
24 Correct 81 ms 12120 KB Output is correct
25 Correct 79 ms 12112 KB Output is correct
26 Correct 81 ms 12112 KB Output is correct
27 Correct 84 ms 12112 KB Output is correct
28 Correct 77 ms 12112 KB Output is correct
29 Correct 73 ms 11988 KB Output is correct
30 Correct 78 ms 12008 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2392 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 111 ms 12116 KB Output is correct
62 Correct 113 ms 12124 KB Output is correct
63 Correct 92 ms 12124 KB Output is correct
64 Correct 119 ms 12120 KB Output is correct
65 Correct 113 ms 12116 KB Output is correct
66 Correct 114 ms 12112 KB Output is correct
67 Correct 112 ms 12060 KB Output is correct
68 Correct 81 ms 12116 KB Output is correct
69 Correct 98 ms 12152 KB Output is correct
70 Correct 78 ms 11860 KB Output is correct