Submission #604273

# Submission time Handle Problem Language Result Execution time Memory
604273 2022-07-25T02:31:25 Z super_j6 Feast (NOI19_feast) C++14
100 / 100
126 ms 10404 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second
 
const int mxn = 300001;
int n, k;
ll a[mxn];
pi dp[mxn];
 
pi sol(ll x){
	pi p = dp[0];
	for(int i = 1; i <= n; i++){
		dp[i] = dp[i - 1];
		if(p.f + a[i] - x > dp[i].f) dp[i] = {p.f + a[i] - x, p.s + 1};
		if(dp[i].f - a[i] > p.f) p = {dp[i].f - a[i], dp[i].s};
	}
	return dp[n];
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1];
	
	ll l = -1, r = 0x3f3f3f3f3f3f;
	while(r - l > 1){
		ll mid = l + (r - l) / 2;
		if(sol(mid).s <= k) r = mid; 
		else l = mid;
	}
	
	pi p = sol(r);
	
	cout << (p.f + k * r) << endl;
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 7108 KB Output is correct
2 Correct 51 ms 7260 KB Output is correct
3 Correct 52 ms 7344 KB Output is correct
4 Correct 52 ms 7304 KB Output is correct
5 Correct 55 ms 7324 KB Output is correct
6 Correct 54 ms 7116 KB Output is correct
7 Correct 53 ms 7116 KB Output is correct
8 Correct 57 ms 7276 KB Output is correct
9 Correct 51 ms 7204 KB Output is correct
10 Correct 50 ms 7236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 7184 KB Output is correct
2 Correct 56 ms 7336 KB Output is correct
3 Correct 54 ms 7168 KB Output is correct
4 Correct 59 ms 7240 KB Output is correct
5 Correct 64 ms 7144 KB Output is correct
6 Correct 47 ms 7124 KB Output is correct
7 Correct 47 ms 7252 KB Output is correct
8 Correct 51 ms 7252 KB Output is correct
9 Correct 50 ms 7064 KB Output is correct
10 Correct 51 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 7272 KB Output is correct
2 Correct 87 ms 10164 KB Output is correct
3 Correct 89 ms 10260 KB Output is correct
4 Correct 91 ms 10188 KB Output is correct
5 Correct 85 ms 10264 KB Output is correct
6 Correct 91 ms 10324 KB Output is correct
7 Correct 104 ms 10316 KB Output is correct
8 Correct 84 ms 10264 KB Output is correct
9 Correct 89 ms 10380 KB Output is correct
10 Correct 86 ms 10368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 244 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 244 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 244 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 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 2 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 336 KB Output is correct
28 Correct 1 ms 360 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 7108 KB Output is correct
2 Correct 51 ms 7260 KB Output is correct
3 Correct 52 ms 7344 KB Output is correct
4 Correct 52 ms 7304 KB Output is correct
5 Correct 55 ms 7324 KB Output is correct
6 Correct 54 ms 7116 KB Output is correct
7 Correct 53 ms 7116 KB Output is correct
8 Correct 57 ms 7276 KB Output is correct
9 Correct 51 ms 7204 KB Output is correct
10 Correct 50 ms 7236 KB Output is correct
11 Correct 53 ms 7184 KB Output is correct
12 Correct 56 ms 7336 KB Output is correct
13 Correct 54 ms 7168 KB Output is correct
14 Correct 59 ms 7240 KB Output is correct
15 Correct 64 ms 7144 KB Output is correct
16 Correct 47 ms 7124 KB Output is correct
17 Correct 47 ms 7252 KB Output is correct
18 Correct 51 ms 7252 KB Output is correct
19 Correct 50 ms 7064 KB Output is correct
20 Correct 51 ms 7244 KB Output is correct
21 Correct 83 ms 7272 KB Output is correct
22 Correct 87 ms 10164 KB Output is correct
23 Correct 89 ms 10260 KB Output is correct
24 Correct 91 ms 10188 KB Output is correct
25 Correct 85 ms 10264 KB Output is correct
26 Correct 91 ms 10324 KB Output is correct
27 Correct 104 ms 10316 KB Output is correct
28 Correct 84 ms 10264 KB Output is correct
29 Correct 89 ms 10380 KB Output is correct
30 Correct 86 ms 10368 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 244 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 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 2 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 336 KB Output is correct
58 Correct 1 ms 360 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 116 ms 10160 KB Output is correct
62 Correct 108 ms 10404 KB Output is correct
63 Correct 97 ms 10060 KB Output is correct
64 Correct 121 ms 10324 KB Output is correct
65 Correct 121 ms 10316 KB Output is correct
66 Correct 120 ms 10228 KB Output is correct
67 Correct 126 ms 10048 KB Output is correct
68 Correct 97 ms 10336 KB Output is correct
69 Correct 88 ms 10144 KB Output is correct
70 Correct 82 ms 10096 KB Output is correct