# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103236 | 2024-10-20T15:04:35 Z | khoaha123 | Feast (NOI19_feast) | C++14 | 297 ms | 137544 KB |
#include <bits/stdc++.h> #define endl '\n' #define ii pair<int,int> #define task "BANQUET" #define all(x) x.begin(),x.end() #define MASK(x) (1 << (x)) #define int long long using namespace std; const int N = 3e5 + 5; const int LOG = 20; const int mod = 998244353; const long long INF = 1e18; int n,a[N],s[N]; int k; void subtask1(void){ int sum = 0; for (int i = 1; i <= n; ++i) sum += a[i]; cout << sum; } void subtask2(void){ int pos = -1; for (int i = 1; i <= n; ++i){ if (a[i] < 0){ pos = i;break; } } if (pos == -1){ subtask1();return; } int sum = 0; for (int i = 1; i <= n; ++i) sum += a[i]; if (k == 1){ int sum1 = 0,sum2 = 0; for (int i = 1; i < pos; ++i) sum1 += a[i]; for (int i = pos+1; i <= n; ++i) sum2 += a[i]; cout << max(sum1,max(sum2,sum)); } else { cout << max(sum,sum - a[pos]); } } void subtask3(void){ int best = 0; int sum = 0; for (int i = 1; i <= n; ++i){ sum = max(a[i],sum + a[i]); best = max(best,sum); } cout << best; } long long Rand(long long l, long long r) { long long res = 0; for (int i= 1; i <= 4; ++i) res = (res << 15) ^ (rand() & ((1 << 15) - 1)); return l + res % (r-l+1); } int f[2005][2005],g[2005][2005]; void subtask6(void){ int ans = 0; for (int i = 1; i <= n; ++i){ for (int j = 1; j <= k; ++j){ f[i][j] = f[i-1][j] + a[i]; if (j >= 1) f[i][j] = max(f[i][j],g[i-1][j-1] + a[i]); g[i][j] = max(g[i-1][j],f[i][j]); ans = max(ans,g[i][j]); } } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); freopen(task".OUT","w",stdout); } srand(time(NULL)); cin >> n >> k; int sub1 = 0,am = 0; for (int i = 1; i <= n; ++i){ cin >> a[i]; //a[i] = Rand(-1000000000,1000000000); if (a[i] >= 0) sub1++; else am++; s[i] = s[i-1] + a[i]; } if (sub1 == n){ subtask1(); return 0; } if (k == 1){ subtask3(); return 0; } if (am == 1){ subtask2(); return 0; } subtask6(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 6224 KB | Output is correct |
2 | Correct | 22 ms | 6200 KB | Output is correct |
3 | Correct | 26 ms | 6224 KB | Output is correct |
4 | Correct | 24 ms | 6296 KB | Output is correct |
5 | Correct | 23 ms | 6224 KB | Output is correct |
6 | Correct | 22 ms | 6224 KB | Output is correct |
7 | Correct | 22 ms | 6224 KB | Output is correct |
8 | Correct | 23 ms | 6156 KB | Output is correct |
9 | Correct | 22 ms | 6224 KB | Output is correct |
10 | Correct | 23 ms | 6140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 6392 KB | Output is correct |
2 | Correct | 15 ms | 6224 KB | Output is correct |
3 | Correct | 16 ms | 6224 KB | Output is correct |
4 | Correct | 14 ms | 6252 KB | Output is correct |
5 | Correct | 22 ms | 6224 KB | Output is correct |
6 | Correct | 15 ms | 6224 KB | Output is correct |
7 | Correct | 14 ms | 6236 KB | Output is correct |
8 | Correct | 21 ms | 6224 KB | Output is correct |
9 | Correct | 20 ms | 6180 KB | Output is correct |
10 | Correct | 14 ms | 6224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 6108 KB | Output is correct |
2 | Correct | 23 ms | 6060 KB | Output is correct |
3 | Correct | 30 ms | 6224 KB | Output is correct |
4 | Correct | 23 ms | 6224 KB | Output is correct |
5 | Correct | 23 ms | 6224 KB | Output is correct |
6 | Correct | 25 ms | 6220 KB | Output is correct |
7 | Correct | 23 ms | 6224 KB | Output is correct |
8 | Correct | 23 ms | 6224 KB | Output is correct |
9 | Correct | 23 ms | 6224 KB | Output is correct |
10 | Correct | 30 ms | 6332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4432 KB | Output is correct |
2 | Correct | 1 ms | 6992 KB | Output is correct |
3 | Correct | 1 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 6736 KB | Output is correct |
5 | Correct | 1 ms | 6992 KB | Output is correct |
6 | Correct | 1 ms | 6736 KB | Output is correct |
7 | Correct | 2 ms | 6992 KB | Output is correct |
8 | Correct | 1 ms | 6736 KB | Output is correct |
9 | Correct | 1 ms | 4432 KB | Output is correct |
10 | Correct | 1 ms | 6736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4432 KB | Output is correct |
2 | Correct | 1 ms | 6992 KB | Output is correct |
3 | Correct | 1 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 6736 KB | Output is correct |
5 | Correct | 1 ms | 6992 KB | Output is correct |
6 | Correct | 1 ms | 6736 KB | Output is correct |
7 | Correct | 2 ms | 6992 KB | Output is correct |
8 | Correct | 1 ms | 6736 KB | Output is correct |
9 | Correct | 1 ms | 4432 KB | Output is correct |
10 | Correct | 1 ms | 6736 KB | Output is correct |
11 | Correct | 2 ms | 15184 KB | Output is correct |
12 | Correct | 2 ms | 13136 KB | Output is correct |
13 | Correct | 2 ms | 13136 KB | Output is correct |
14 | Correct | 2 ms | 15184 KB | Output is correct |
15 | Correct | 2 ms | 13136 KB | Output is correct |
16 | Correct | 2 ms | 13136 KB | Output is correct |
17 | Correct | 2 ms | 15184 KB | Output is correct |
18 | Correct | 2 ms | 13136 KB | Output is correct |
19 | Correct | 3 ms | 13308 KB | Output is correct |
20 | Correct | 2 ms | 15184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4432 KB | Output is correct |
2 | Correct | 1 ms | 6992 KB | Output is correct |
3 | Correct | 1 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 6736 KB | Output is correct |
5 | Correct | 1 ms | 6992 KB | Output is correct |
6 | Correct | 1 ms | 6736 KB | Output is correct |
7 | Correct | 2 ms | 6992 KB | Output is correct |
8 | Correct | 1 ms | 6736 KB | Output is correct |
9 | Correct | 1 ms | 4432 KB | Output is correct |
10 | Correct | 1 ms | 6736 KB | Output is correct |
11 | Correct | 2 ms | 15184 KB | Output is correct |
12 | Correct | 2 ms | 13136 KB | Output is correct |
13 | Correct | 2 ms | 13136 KB | Output is correct |
14 | Correct | 2 ms | 15184 KB | Output is correct |
15 | Correct | 2 ms | 13136 KB | Output is correct |
16 | Correct | 2 ms | 13136 KB | Output is correct |
17 | Correct | 2 ms | 15184 KB | Output is correct |
18 | Correct | 2 ms | 13136 KB | Output is correct |
19 | Correct | 3 ms | 13308 KB | Output is correct |
20 | Correct | 2 ms | 15184 KB | Output is correct |
21 | Correct | 7 ms | 64592 KB | Output is correct |
22 | Correct | 12 ms | 65616 KB | Output is correct |
23 | Correct | 8 ms | 64592 KB | Output is correct |
24 | Correct | 7 ms | 64592 KB | Output is correct |
25 | Correct | 8 ms | 64848 KB | Output is correct |
26 | Correct | 7 ms | 64600 KB | Output is correct |
27 | Correct | 7 ms | 64848 KB | Output is correct |
28 | Correct | 7 ms | 64468 KB | Output is correct |
29 | Correct | 7 ms | 64336 KB | Output is correct |
30 | Correct | 7 ms | 64336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 6224 KB | Output is correct |
2 | Correct | 22 ms | 6200 KB | Output is correct |
3 | Correct | 26 ms | 6224 KB | Output is correct |
4 | Correct | 24 ms | 6296 KB | Output is correct |
5 | Correct | 23 ms | 6224 KB | Output is correct |
6 | Correct | 22 ms | 6224 KB | Output is correct |
7 | Correct | 22 ms | 6224 KB | Output is correct |
8 | Correct | 23 ms | 6156 KB | Output is correct |
9 | Correct | 22 ms | 6224 KB | Output is correct |
10 | Correct | 23 ms | 6140 KB | Output is correct |
11 | Correct | 14 ms | 6392 KB | Output is correct |
12 | Correct | 15 ms | 6224 KB | Output is correct |
13 | Correct | 16 ms | 6224 KB | Output is correct |
14 | Correct | 14 ms | 6252 KB | Output is correct |
15 | Correct | 22 ms | 6224 KB | Output is correct |
16 | Correct | 15 ms | 6224 KB | Output is correct |
17 | Correct | 14 ms | 6236 KB | Output is correct |
18 | Correct | 21 ms | 6224 KB | Output is correct |
19 | Correct | 20 ms | 6180 KB | Output is correct |
20 | Correct | 14 ms | 6224 KB | Output is correct |
21 | Correct | 24 ms | 6108 KB | Output is correct |
22 | Correct | 23 ms | 6060 KB | Output is correct |
23 | Correct | 30 ms | 6224 KB | Output is correct |
24 | Correct | 23 ms | 6224 KB | Output is correct |
25 | Correct | 23 ms | 6224 KB | Output is correct |
26 | Correct | 25 ms | 6220 KB | Output is correct |
27 | Correct | 23 ms | 6224 KB | Output is correct |
28 | Correct | 23 ms | 6224 KB | Output is correct |
29 | Correct | 23 ms | 6224 KB | Output is correct |
30 | Correct | 30 ms | 6332 KB | Output is correct |
31 | Correct | 1 ms | 4432 KB | Output is correct |
32 | Correct | 1 ms | 6992 KB | Output is correct |
33 | Correct | 1 ms | 6736 KB | Output is correct |
34 | Correct | 1 ms | 6736 KB | Output is correct |
35 | Correct | 1 ms | 6992 KB | Output is correct |
36 | Correct | 1 ms | 6736 KB | Output is correct |
37 | Correct | 2 ms | 6992 KB | Output is correct |
38 | Correct | 1 ms | 6736 KB | Output is correct |
39 | Correct | 1 ms | 4432 KB | Output is correct |
40 | Correct | 1 ms | 6736 KB | Output is correct |
41 | Correct | 2 ms | 15184 KB | Output is correct |
42 | Correct | 2 ms | 13136 KB | Output is correct |
43 | Correct | 2 ms | 13136 KB | Output is correct |
44 | Correct | 2 ms | 15184 KB | Output is correct |
45 | Correct | 2 ms | 13136 KB | Output is correct |
46 | Correct | 2 ms | 13136 KB | Output is correct |
47 | Correct | 2 ms | 15184 KB | Output is correct |
48 | Correct | 2 ms | 13136 KB | Output is correct |
49 | Correct | 3 ms | 13308 KB | Output is correct |
50 | Correct | 2 ms | 15184 KB | Output is correct |
51 | Correct | 7 ms | 64592 KB | Output is correct |
52 | Correct | 12 ms | 65616 KB | Output is correct |
53 | Correct | 8 ms | 64592 KB | Output is correct |
54 | Correct | 7 ms | 64592 KB | Output is correct |
55 | Correct | 8 ms | 64848 KB | Output is correct |
56 | Correct | 7 ms | 64600 KB | Output is correct |
57 | Correct | 7 ms | 64848 KB | Output is correct |
58 | Correct | 7 ms | 64468 KB | Output is correct |
59 | Correct | 7 ms | 64336 KB | Output is correct |
60 | Correct | 7 ms | 64336 KB | Output is correct |
61 | Runtime error | 297 ms | 137544 KB | Execution killed with signal 11 |
62 | Halted | 0 ms | 0 KB | - |