# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857621 |
2023-10-06T14:23:22 Z |
hungnt |
Feast (NOI19_feast) |
C++17 |
|
81 ms |
132920 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, k;
int a[N];
long long dp[2003][2003][2];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
int cntam = 0;
long long s = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
cntam += (a[i] < 0);
s += a[i];
}
if(!cntam)
{
cout << s;
return 0;
}
if(cntam == 1)
{
long long l = 0, r = 0;
int id = 1;
while(a[id] >= 0)
{
l += id;
id++;
}
id = n;
while(a[id] >= 0)
{
r += id;
id--;
}
if(k == 1) cout << max({l, r, s});
else cout << l + r;
return 0;
}
long long ans=0;
dp[0][0][1] = 0;
dp[0][0][0] = 0;
for(int i = 1; i <= n; i++)
{
dp[i][0][0] = 0;
for(int j = 1; j <= k; j++)
{
dp[i][j][0] = max(dp[i - 1][j][1], dp[i - 1][j][0]);
dp[i][j][1] = max(dp[i - 1][j][1], dp[i - 1][j - 1][0]) + a[i];
ans = max({ans, dp[i][j][0], dp[i][j][1]});
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5436 KB |
Output is correct |
2 |
Correct |
23 ms |
5464 KB |
Output is correct |
3 |
Correct |
23 ms |
5684 KB |
Output is correct |
4 |
Correct |
23 ms |
5440 KB |
Output is correct |
5 |
Correct |
22 ms |
5456 KB |
Output is correct |
6 |
Correct |
23 ms |
5288 KB |
Output is correct |
7 |
Correct |
22 ms |
5304 KB |
Output is correct |
8 |
Correct |
24 ms |
5428 KB |
Output is correct |
9 |
Correct |
22 ms |
5208 KB |
Output is correct |
10 |
Correct |
23 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
3676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
81 ms |
132920 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
7004 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
7004 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
12636 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12632 KB |
Output is correct |
15 |
Correct |
1 ms |
12636 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12636 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
7004 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
12636 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12632 KB |
Output is correct |
15 |
Correct |
1 ms |
12636 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12636 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
8 ms |
64288 KB |
Output is correct |
22 |
Correct |
13 ms |
64092 KB |
Output is correct |
23 |
Correct |
9 ms |
64092 KB |
Output is correct |
24 |
Correct |
8 ms |
64092 KB |
Output is correct |
25 |
Correct |
8 ms |
64092 KB |
Output is correct |
26 |
Correct |
8 ms |
64068 KB |
Output is correct |
27 |
Correct |
8 ms |
64092 KB |
Output is correct |
28 |
Correct |
7 ms |
64092 KB |
Output is correct |
29 |
Correct |
7 ms |
63968 KB |
Output is correct |
30 |
Correct |
7 ms |
63972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5436 KB |
Output is correct |
2 |
Correct |
23 ms |
5464 KB |
Output is correct |
3 |
Correct |
23 ms |
5684 KB |
Output is correct |
4 |
Correct |
23 ms |
5440 KB |
Output is correct |
5 |
Correct |
22 ms |
5456 KB |
Output is correct |
6 |
Correct |
23 ms |
5288 KB |
Output is correct |
7 |
Correct |
22 ms |
5304 KB |
Output is correct |
8 |
Correct |
24 ms |
5428 KB |
Output is correct |
9 |
Correct |
22 ms |
5208 KB |
Output is correct |
10 |
Correct |
23 ms |
5376 KB |
Output is correct |
11 |
Incorrect |
15 ms |
3676 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |