Submission #755280

# Submission time Handle Problem Language Result Execution time Memory
755280 2023-06-09T16:38:07 Z He_Huanglu Feast (NOI19_feast) C++17
100 / 100
313 ms 18628 KB
#include <bits/stdc++.h>
#define ii pair<long long, int>
#define fi first
#define se second
using namespace std;

const int N = 3e5 + 5;
int n, k, a[N];
long long ans, tax, l, r = 1e18;
ii f[N][3];

main () {
    cin.tie(0)->sync_with_stdio(0);
    if(fopen("task.inp", "r")) {
        freopen("task.inp", "r", stdin);
        freopen("wa.out", "w", stdout);
    }
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    f[1][1].fi = -1e18;
    while (l <= r) {
        tax = (l + r) >> 1;
        f[1][2] = {a[1] - tax, 1};
        for(int i = 2; i <= n; i++) {
            f[i][0] = max({f[i - 1][0], f[i - 1][1], f[i - 1][2]});
            f[i][1] = max(f[i - 1][1], f[i - 1][2]);
            f[i][1].fi += a[i];
            f[i][2] = {f[i][0].fi + a[i] - tax, f[i][0].se + 1};
        }
        ii tmp = max({f[n][0], f[n][1], f[n][2]});
        if(tmp.se <= k) {
            ans = tmp.fi + tax * tmp.se;
            r = tax - 1;
        }
        else l = tax + 1;
    }
    cout << ans;
}

Compilation message

feast.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main () {
      | ^~~~
feast.cpp: In function 'int main()':
feast.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen("wa.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 272 ms 17900 KB Output is correct
2 Correct 273 ms 18340 KB Output is correct
3 Correct 282 ms 18436 KB Output is correct
4 Correct 274 ms 18312 KB Output is correct
5 Correct 286 ms 18252 KB Output is correct
6 Correct 269 ms 17996 KB Output is correct
7 Correct 292 ms 17900 KB Output is correct
8 Correct 279 ms 18276 KB Output is correct
9 Correct 285 ms 17956 KB Output is correct
10 Correct 282 ms 18136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 269 ms 16320 KB Output is correct
2 Correct 269 ms 16676 KB Output is correct
3 Correct 281 ms 16300 KB Output is correct
4 Correct 264 ms 16440 KB Output is correct
5 Correct 281 ms 17928 KB Output is correct
6 Correct 262 ms 16288 KB Output is correct
7 Correct 272 ms 16712 KB Output is correct
8 Correct 284 ms 18372 KB Output is correct
9 Correct 276 ms 17760 KB Output is correct
10 Correct 264 ms 16600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 18428 KB Output is correct
2 Correct 266 ms 18272 KB Output is correct
3 Correct 280 ms 18380 KB Output is correct
4 Correct 268 ms 18188 KB Output is correct
5 Correct 291 ms 18368 KB Output is correct
6 Correct 294 ms 18380 KB Output is correct
7 Correct 279 ms 18552 KB Output is correct
8 Correct 277 ms 18348 KB Output is correct
9 Correct 276 ms 18604 KB Output is correct
10 Correct 301 ms 18552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 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 340 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 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 340 KB Output is correct
10 Correct 1 ms 284 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 328 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 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 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 340 KB Output is correct
10 Correct 1 ms 284 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 328 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 3 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 272 ms 17900 KB Output is correct
2 Correct 273 ms 18340 KB Output is correct
3 Correct 282 ms 18436 KB Output is correct
4 Correct 274 ms 18312 KB Output is correct
5 Correct 286 ms 18252 KB Output is correct
6 Correct 269 ms 17996 KB Output is correct
7 Correct 292 ms 17900 KB Output is correct
8 Correct 279 ms 18276 KB Output is correct
9 Correct 285 ms 17956 KB Output is correct
10 Correct 282 ms 18136 KB Output is correct
11 Correct 269 ms 16320 KB Output is correct
12 Correct 269 ms 16676 KB Output is correct
13 Correct 281 ms 16300 KB Output is correct
14 Correct 264 ms 16440 KB Output is correct
15 Correct 281 ms 17928 KB Output is correct
16 Correct 262 ms 16288 KB Output is correct
17 Correct 272 ms 16712 KB Output is correct
18 Correct 284 ms 18372 KB Output is correct
19 Correct 276 ms 17760 KB Output is correct
20 Correct 264 ms 16600 KB Output is correct
21 Correct 289 ms 18428 KB Output is correct
22 Correct 266 ms 18272 KB Output is correct
23 Correct 280 ms 18380 KB Output is correct
24 Correct 268 ms 18188 KB Output is correct
25 Correct 291 ms 18368 KB Output is correct
26 Correct 294 ms 18380 KB Output is correct
27 Correct 279 ms 18552 KB Output is correct
28 Correct 277 ms 18348 KB Output is correct
29 Correct 276 ms 18604 KB Output is correct
30 Correct 301 ms 18552 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 332 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 340 KB Output is correct
40 Correct 1 ms 284 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 328 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 3 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 3 ms 348 KB Output is correct
56 Correct 3 ms 340 KB Output is correct
57 Correct 3 ms 340 KB Output is correct
58 Correct 3 ms 340 KB Output is correct
59 Correct 3 ms 340 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 308 ms 18168 KB Output is correct
62 Correct 313 ms 18628 KB Output is correct
63 Correct 273 ms 18120 KB Output is correct
64 Correct 298 ms 18484 KB Output is correct
65 Correct 286 ms 18388 KB Output is correct
66 Correct 296 ms 18500 KB Output is correct
67 Correct 287 ms 18148 KB Output is correct
68 Correct 281 ms 18380 KB Output is correct
69 Correct 270 ms 18252 KB Output is correct
70 Correct 277 ms 18052 KB Output is correct