Submission #387415

# Submission time Handle Problem Language Result Execution time Memory
387415 2021-04-08T11:08:09 Z saarang123 Feast (NOI19_feast) C++17
100 / 100
320 ms 13108 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 3 * 100 * 1000 + 3;
int a[mxn], p[mxn], n, k;

array<int, 2> check(int m) {
	vector<int> dp(n + 1), cnt(n + 1);
	int besti = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1], cnt[i] = cnt[i - 1];
        if (dp[i] < dp[besti] + p[i] - p[besti] - m) {
            dp[i] = dp[besti] + p[i] - p[besti] - m;
            cnt[i] = cnt[besti] + 1;
        }
        if (dp[besti] - p[besti] < dp[i] - p[i]) besti = i;
    }
	return {dp[n], cnt[n]};
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
    	cin >> a[i];
    	p[i] = p[i - 1] + a[i];
    }
    int mn = 0, mx = 1e18;
    while(mn < mx) {
    	int mid = (mn + mx) >> 1;
    	if(check(mid)[1] > k)
    		mn = mid + 1;
    	else
    		mx = mid;
    }
    cout << check(mn)[0] + mn * k << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12388 KB Output is correct
2 Correct 277 ms 12616 KB Output is correct
3 Correct 279 ms 12880 KB Output is correct
4 Correct 277 ms 12660 KB Output is correct
5 Correct 273 ms 12676 KB Output is correct
6 Correct 268 ms 12372 KB Output is correct
7 Correct 268 ms 12444 KB Output is correct
8 Correct 269 ms 12644 KB Output is correct
9 Correct 267 ms 12412 KB Output is correct
10 Correct 270 ms 12524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 10904 KB Output is correct
2 Correct 250 ms 11068 KB Output is correct
3 Correct 246 ms 10732 KB Output is correct
4 Correct 253 ms 10868 KB Output is correct
5 Correct 270 ms 12632 KB Output is correct
6 Correct 251 ms 11124 KB Output is correct
7 Correct 262 ms 11012 KB Output is correct
8 Correct 273 ms 12772 KB Output is correct
9 Correct 271 ms 12372 KB Output is correct
10 Correct 258 ms 10944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 12812 KB Output is correct
2 Correct 261 ms 12828 KB Output is correct
3 Correct 257 ms 12792 KB Output is correct
4 Correct 252 ms 12892 KB Output is correct
5 Correct 254 ms 12764 KB Output is correct
6 Correct 255 ms 12828 KB Output is correct
7 Correct 258 ms 12916 KB Output is correct
8 Correct 254 ms 12964 KB Output is correct
9 Correct 263 ms 12972 KB Output is correct
10 Correct 252 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12388 KB Output is correct
2 Correct 277 ms 12616 KB Output is correct
3 Correct 279 ms 12880 KB Output is correct
4 Correct 277 ms 12660 KB Output is correct
5 Correct 273 ms 12676 KB Output is correct
6 Correct 268 ms 12372 KB Output is correct
7 Correct 268 ms 12444 KB Output is correct
8 Correct 269 ms 12644 KB Output is correct
9 Correct 267 ms 12412 KB Output is correct
10 Correct 270 ms 12524 KB Output is correct
11 Correct 240 ms 10904 KB Output is correct
12 Correct 250 ms 11068 KB Output is correct
13 Correct 246 ms 10732 KB Output is correct
14 Correct 253 ms 10868 KB Output is correct
15 Correct 270 ms 12632 KB Output is correct
16 Correct 251 ms 11124 KB Output is correct
17 Correct 262 ms 11012 KB Output is correct
18 Correct 273 ms 12772 KB Output is correct
19 Correct 271 ms 12372 KB Output is correct
20 Correct 258 ms 10944 KB Output is correct
21 Correct 249 ms 12812 KB Output is correct
22 Correct 261 ms 12828 KB Output is correct
23 Correct 257 ms 12792 KB Output is correct
24 Correct 252 ms 12892 KB Output is correct
25 Correct 254 ms 12764 KB Output is correct
26 Correct 255 ms 12828 KB Output is correct
27 Correct 258 ms 12916 KB Output is correct
28 Correct 254 ms 12964 KB Output is correct
29 Correct 263 ms 12972 KB Output is correct
30 Correct 252 ms 12928 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 2 ms 364 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 2 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 2 ms 492 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 2 ms 492 KB Output is correct
55 Correct 3 ms 492 KB Output is correct
56 Correct 2 ms 492 KB Output is correct
57 Correct 2 ms 492 KB Output is correct
58 Correct 2 ms 492 KB Output is correct
59 Correct 2 ms 492 KB Output is correct
60 Correct 2 ms 492 KB Output is correct
61 Correct 297 ms 12708 KB Output is correct
62 Correct 320 ms 13108 KB Output is correct
63 Correct 266 ms 12580 KB Output is correct
64 Correct 298 ms 12848 KB Output is correct
65 Correct 303 ms 12916 KB Output is correct
66 Correct 291 ms 12996 KB Output is correct
67 Correct 287 ms 12728 KB Output is correct
68 Correct 257 ms 12916 KB Output is correct
69 Correct 256 ms 12596 KB Output is correct
70 Correct 251 ms 12532 KB Output is correct