# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
646184 |
2022-09-29T04:31:52 Z |
kith14 |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
55252 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back
const ll N = 3e5+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], tot;
string s, s1, s2, ye = "YA", no = "TIDAK";
void input(){
cin >> n >> m;
repp(i,1,n){
cin >> ar[i];
tot += (ar[i] < 0);
}
}
void t1(){
ll sum1 = 0, sum2 = 0, red = 0;
repp(i,1,n){
if (ar[i] < 0) red = ar[i];
else{
if (red == 0) sum1 += ar[i];
else sum2 += ar[i];
}
}
if (m >= 2) cout << sum1+sum2 << endl;
else cout << max(sum1,max(sum2,sum1+sum2+red)) << endl;
exit(0);
}
void knd(){
ll ans = 0, cur = 0;
repp(i,1,n){
cur += ar[i];
cur = max(cur,0LL);
ans = max(ans,cur);
}
cout << ans << endl;
exit(0);
}
void solve(){
if (tot <= 1) t1();
else if (m== 1) knd();
ll dp[n+5][m+5], prec[n+5][n+5];
repp(i,1,n){
ll cur = 0, maxi = 0;
repp(j,i,n){
cur += ar[j];
maxi = max(maxi,cur);
cur = max(0LL,cur);
prec[i][j] = maxi;
}
}
memset(dp,0,sizeof(dp));
repm(idx,n,1){
repp(rem,1,m){
dp[idx][rem] = dp[idx+1][rem];
repp(i,idx,n){
dp[idx][rem] = max(dp[idx][rem],prec[idx][i]+dp[i+1][rem-1]);
}
}
}
cout << dp[1][m] << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//cin >> tc;
while(tc--){
input();
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5324 KB |
Output is correct |
2 |
Correct |
28 ms |
5432 KB |
Output is correct |
3 |
Correct |
28 ms |
5520 KB |
Output is correct |
4 |
Correct |
29 ms |
5556 KB |
Output is correct |
5 |
Correct |
32 ms |
5468 KB |
Output is correct |
6 |
Correct |
29 ms |
5328 KB |
Output is correct |
7 |
Correct |
28 ms |
5264 KB |
Output is correct |
8 |
Correct |
29 ms |
5408 KB |
Output is correct |
9 |
Correct |
27 ms |
5292 KB |
Output is correct |
10 |
Correct |
32 ms |
5436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2624 KB |
Output is correct |
2 |
Correct |
23 ms |
3796 KB |
Output is correct |
3 |
Correct |
18 ms |
3624 KB |
Output is correct |
4 |
Correct |
18 ms |
3736 KB |
Output is correct |
5 |
Correct |
28 ms |
5384 KB |
Output is correct |
6 |
Correct |
18 ms |
3644 KB |
Output is correct |
7 |
Correct |
18 ms |
3756 KB |
Output is correct |
8 |
Correct |
29 ms |
5436 KB |
Output is correct |
9 |
Correct |
28 ms |
5340 KB |
Output is correct |
10 |
Correct |
18 ms |
3876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2632 KB |
Output is correct |
2 |
Correct |
31 ms |
5504 KB |
Output is correct |
3 |
Correct |
31 ms |
5580 KB |
Output is correct |
4 |
Correct |
31 ms |
5560 KB |
Output is correct |
5 |
Correct |
33 ms |
5620 KB |
Output is correct |
6 |
Correct |
31 ms |
5584 KB |
Output is correct |
7 |
Correct |
30 ms |
5608 KB |
Output is correct |
8 |
Correct |
35 ms |
5548 KB |
Output is correct |
9 |
Correct |
31 ms |
5672 KB |
Output is correct |
10 |
Correct |
32 ms |
5652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1008 KB |
Output is correct |
13 |
Correct |
2 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
980 KB |
Output is correct |
15 |
Correct |
3 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
2 ms |
1060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1008 KB |
Output is correct |
13 |
Correct |
2 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
980 KB |
Output is correct |
15 |
Correct |
3 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
2 ms |
1060 KB |
Output is correct |
21 |
Correct |
610 ms |
33120 KB |
Output is correct |
22 |
Execution timed out |
1058 ms |
55252 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5324 KB |
Output is correct |
2 |
Correct |
28 ms |
5432 KB |
Output is correct |
3 |
Correct |
28 ms |
5520 KB |
Output is correct |
4 |
Correct |
29 ms |
5556 KB |
Output is correct |
5 |
Correct |
32 ms |
5468 KB |
Output is correct |
6 |
Correct |
29 ms |
5328 KB |
Output is correct |
7 |
Correct |
28 ms |
5264 KB |
Output is correct |
8 |
Correct |
29 ms |
5408 KB |
Output is correct |
9 |
Correct |
27 ms |
5292 KB |
Output is correct |
10 |
Correct |
32 ms |
5436 KB |
Output is correct |
11 |
Correct |
18 ms |
2624 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
18 ms |
3624 KB |
Output is correct |
14 |
Correct |
18 ms |
3736 KB |
Output is correct |
15 |
Correct |
28 ms |
5384 KB |
Output is correct |
16 |
Correct |
18 ms |
3644 KB |
Output is correct |
17 |
Correct |
18 ms |
3756 KB |
Output is correct |
18 |
Correct |
29 ms |
5436 KB |
Output is correct |
19 |
Correct |
28 ms |
5340 KB |
Output is correct |
20 |
Correct |
18 ms |
3876 KB |
Output is correct |
21 |
Correct |
33 ms |
2632 KB |
Output is correct |
22 |
Correct |
31 ms |
5504 KB |
Output is correct |
23 |
Correct |
31 ms |
5580 KB |
Output is correct |
24 |
Correct |
31 ms |
5560 KB |
Output is correct |
25 |
Correct |
33 ms |
5620 KB |
Output is correct |
26 |
Correct |
31 ms |
5584 KB |
Output is correct |
27 |
Correct |
30 ms |
5608 KB |
Output is correct |
28 |
Correct |
35 ms |
5548 KB |
Output is correct |
29 |
Correct |
31 ms |
5672 KB |
Output is correct |
30 |
Correct |
32 ms |
5652 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
3 ms |
1108 KB |
Output is correct |
42 |
Correct |
4 ms |
1008 KB |
Output is correct |
43 |
Correct |
2 ms |
852 KB |
Output is correct |
44 |
Correct |
3 ms |
980 KB |
Output is correct |
45 |
Correct |
3 ms |
980 KB |
Output is correct |
46 |
Correct |
2 ms |
852 KB |
Output is correct |
47 |
Correct |
3 ms |
980 KB |
Output is correct |
48 |
Correct |
1 ms |
852 KB |
Output is correct |
49 |
Correct |
1 ms |
852 KB |
Output is correct |
50 |
Correct |
2 ms |
1060 KB |
Output is correct |
51 |
Correct |
610 ms |
33120 KB |
Output is correct |
52 |
Execution timed out |
1058 ms |
55252 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |