# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007999 |
2024-06-26T05:27:46 Z |
Luvidi |
Feast (NOI19_feast) |
C++17 |
|
138 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n,k;
cin>>n>>k;
ll a[n+1],p[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
p[0]=0;
for (int i=1;i<=n;i++)p[i]=p[i-1]+a[i];
int cnt=0,idx;
for (int i=1;i<=n;i++)if(a[i]<0){
cnt++;
idx=i;
}
if(!cnt){
cout<<p[n];
return;
}
if(cnt==1){
if(k==1)cout<<max(p[n],max(p[idx-1],p[n]-p[idx]));
else cout<<p[n]-a[idx];
return;
}
ll dp[n+1][k+1],lrg[n+1];
memset(dp,0,sizeof(dp));
lrg[0]=0;
for (int i=1;i<=n;i++)lrg[i]=max(lrg[i-1],dp[i-1][0]-p[i-1]);
for (int j=1;j<=k;j++){
for (int i=1;i<=n;i++){
dp[i][j]=max(dp[i-1][j],lrg[i]+p[i]);
lrg[i]=max(lrg[i-1],dp[i-1][j]-p[i-1]);
}
}
cout<<dp[n][k];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6484 KB |
Output is correct |
2 |
Correct |
24 ms |
6792 KB |
Output is correct |
3 |
Correct |
24 ms |
6732 KB |
Output is correct |
4 |
Correct |
23 ms |
6740 KB |
Output is correct |
5 |
Correct |
21 ms |
6740 KB |
Output is correct |
6 |
Correct |
23 ms |
6480 KB |
Output is correct |
7 |
Correct |
21 ms |
6428 KB |
Output is correct |
8 |
Correct |
24 ms |
6828 KB |
Output is correct |
9 |
Correct |
22 ms |
6480 KB |
Output is correct |
10 |
Correct |
22 ms |
6740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5716 KB |
Output is correct |
2 |
Correct |
15 ms |
5724 KB |
Output is correct |
3 |
Correct |
14 ms |
5724 KB |
Output is correct |
4 |
Correct |
14 ms |
5604 KB |
Output is correct |
5 |
Correct |
24 ms |
6284 KB |
Output is correct |
6 |
Correct |
15 ms |
5724 KB |
Output is correct |
7 |
Correct |
15 ms |
5808 KB |
Output is correct |
8 |
Correct |
22 ms |
6752 KB |
Output is correct |
9 |
Correct |
26 ms |
6348 KB |
Output is correct |
10 |
Correct |
15 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
13724 KB |
Output is correct |
2 |
Correct |
39 ms |
14872 KB |
Output is correct |
3 |
Correct |
43 ms |
14932 KB |
Output is correct |
4 |
Correct |
30 ms |
14676 KB |
Output is correct |
5 |
Correct |
30 ms |
14784 KB |
Output is correct |
6 |
Correct |
32 ms |
14948 KB |
Output is correct |
7 |
Correct |
30 ms |
14940 KB |
Output is correct |
8 |
Correct |
30 ms |
14928 KB |
Output is correct |
9 |
Correct |
29 ms |
15196 KB |
Output is correct |
10 |
Correct |
39 ms |
15084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
412 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
412 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
456 KB |
Output is correct |
21 |
Correct |
3 ms |
3420 KB |
Output is correct |
22 |
Correct |
26 ms |
25948 KB |
Output is correct |
23 |
Correct |
7 ms |
6392 KB |
Output is correct |
24 |
Correct |
4 ms |
3676 KB |
Output is correct |
25 |
Correct |
5 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
3168 KB |
Output is correct |
27 |
Correct |
5 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
860 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6484 KB |
Output is correct |
2 |
Correct |
24 ms |
6792 KB |
Output is correct |
3 |
Correct |
24 ms |
6732 KB |
Output is correct |
4 |
Correct |
23 ms |
6740 KB |
Output is correct |
5 |
Correct |
21 ms |
6740 KB |
Output is correct |
6 |
Correct |
23 ms |
6480 KB |
Output is correct |
7 |
Correct |
21 ms |
6428 KB |
Output is correct |
8 |
Correct |
24 ms |
6828 KB |
Output is correct |
9 |
Correct |
22 ms |
6480 KB |
Output is correct |
10 |
Correct |
22 ms |
6740 KB |
Output is correct |
11 |
Correct |
14 ms |
5716 KB |
Output is correct |
12 |
Correct |
15 ms |
5724 KB |
Output is correct |
13 |
Correct |
14 ms |
5724 KB |
Output is correct |
14 |
Correct |
14 ms |
5604 KB |
Output is correct |
15 |
Correct |
24 ms |
6284 KB |
Output is correct |
16 |
Correct |
15 ms |
5724 KB |
Output is correct |
17 |
Correct |
15 ms |
5808 KB |
Output is correct |
18 |
Correct |
22 ms |
6752 KB |
Output is correct |
19 |
Correct |
26 ms |
6348 KB |
Output is correct |
20 |
Correct |
15 ms |
5724 KB |
Output is correct |
21 |
Correct |
30 ms |
13724 KB |
Output is correct |
22 |
Correct |
39 ms |
14872 KB |
Output is correct |
23 |
Correct |
43 ms |
14932 KB |
Output is correct |
24 |
Correct |
30 ms |
14676 KB |
Output is correct |
25 |
Correct |
30 ms |
14784 KB |
Output is correct |
26 |
Correct |
32 ms |
14948 KB |
Output is correct |
27 |
Correct |
30 ms |
14940 KB |
Output is correct |
28 |
Correct |
30 ms |
14928 KB |
Output is correct |
29 |
Correct |
29 ms |
15196 KB |
Output is correct |
30 |
Correct |
39 ms |
15084 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
456 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
452 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
604 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
412 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
456 KB |
Output is correct |
51 |
Correct |
3 ms |
3420 KB |
Output is correct |
52 |
Correct |
26 ms |
25948 KB |
Output is correct |
53 |
Correct |
7 ms |
6392 KB |
Output is correct |
54 |
Correct |
4 ms |
3676 KB |
Output is correct |
55 |
Correct |
5 ms |
4956 KB |
Output is correct |
56 |
Correct |
3 ms |
3168 KB |
Output is correct |
57 |
Correct |
5 ms |
4700 KB |
Output is correct |
58 |
Correct |
1 ms |
860 KB |
Output is correct |
59 |
Correct |
1 ms |
860 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Runtime error |
138 ms |
262144 KB |
Execution killed with signal 9 |
62 |
Halted |
0 ms |
0 KB |
- |