# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
938589 |
2024-03-05T10:45:53 Z |
Lilypad |
Feast (NOI19_feast) |
C++14 |
|
102 ms |
68436 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
const ll N = 2003;
ll n,k,sum,b[300005];
ll mins,pos,idx;
vector<ll> a;
ll memo[N][N][2];
ll dp(ll x, ll y, ll stat) {
if(x == idx+1) return 0;
ll tmp = memo[x][y][stat];
if(tmp != -1) return tmp;
if(stat == 0) {
tmp = dp(x+1,y,0);
if(y > 0) {
tmp = max(tmp,dp(x+1,y-1,1)+a[x]);
}
}
else {
tmp = max(dp(x+1,y,0),dp(x+1,y,1)+a[x]);
}
return memo[x][y][stat] = tmp;
}
int main() {
memset(memo,-1,sizeof(memo));
cin >> n >> k;
for(int i=1; i<=n; i++) {
cin >> b[i];
}
a.pb(0);
for(int i=1; i<=n; i++) {
if(b[i] >= 0) {
sum += b[i];
if(mins < 0) {
a.pb(mins);
mins = 0;
}
}
else {
mins += b[i];
if(sum > 0) {
a.pb(sum);
sum = 0;
pos++;
}
}
}
if(sum > 0) {
a.pb(sum);
pos++;
}
if(mins < 0) a.pb(mins);
idx = a.size()-1;
cout << dp(1,k,0) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
65364 KB |
Output is correct |
2 |
Correct |
90 ms |
65312 KB |
Output is correct |
3 |
Correct |
93 ms |
65620 KB |
Output is correct |
4 |
Correct |
94 ms |
65364 KB |
Output is correct |
5 |
Correct |
89 ms |
65360 KB |
Output is correct |
6 |
Correct |
86 ms |
65444 KB |
Output is correct |
7 |
Correct |
97 ms |
65388 KB |
Output is correct |
8 |
Correct |
90 ms |
65364 KB |
Output is correct |
9 |
Correct |
87 ms |
65500 KB |
Output is correct |
10 |
Correct |
96 ms |
65488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
65364 KB |
Output is correct |
2 |
Correct |
65 ms |
65360 KB |
Output is correct |
3 |
Correct |
50 ms |
65364 KB |
Output is correct |
4 |
Correct |
63 ms |
66592 KB |
Output is correct |
5 |
Correct |
91 ms |
68224 KB |
Output is correct |
6 |
Correct |
51 ms |
66540 KB |
Output is correct |
7 |
Correct |
51 ms |
66640 KB |
Output is correct |
8 |
Correct |
102 ms |
68436 KB |
Output is correct |
9 |
Correct |
88 ms |
68176 KB |
Output is correct |
10 |
Correct |
50 ms |
66640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
67732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
64092 KB |
Output is correct |
2 |
Correct |
9 ms |
64088 KB |
Output is correct |
3 |
Correct |
9 ms |
64092 KB |
Output is correct |
4 |
Correct |
8 ms |
64096 KB |
Output is correct |
5 |
Correct |
9 ms |
64092 KB |
Output is correct |
6 |
Correct |
9 ms |
64092 KB |
Output is correct |
7 |
Correct |
9 ms |
64092 KB |
Output is correct |
8 |
Correct |
9 ms |
64176 KB |
Output is correct |
9 |
Correct |
10 ms |
64140 KB |
Output is correct |
10 |
Correct |
10 ms |
64092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
64092 KB |
Output is correct |
2 |
Correct |
9 ms |
64088 KB |
Output is correct |
3 |
Correct |
9 ms |
64092 KB |
Output is correct |
4 |
Correct |
8 ms |
64096 KB |
Output is correct |
5 |
Correct |
9 ms |
64092 KB |
Output is correct |
6 |
Correct |
9 ms |
64092 KB |
Output is correct |
7 |
Correct |
9 ms |
64092 KB |
Output is correct |
8 |
Correct |
9 ms |
64176 KB |
Output is correct |
9 |
Correct |
10 ms |
64140 KB |
Output is correct |
10 |
Correct |
10 ms |
64092 KB |
Output is correct |
11 |
Correct |
9 ms |
64092 KB |
Output is correct |
12 |
Correct |
8 ms |
64088 KB |
Output is correct |
13 |
Correct |
9 ms |
64088 KB |
Output is correct |
14 |
Correct |
9 ms |
64088 KB |
Output is correct |
15 |
Correct |
9 ms |
64092 KB |
Output is correct |
16 |
Correct |
9 ms |
64088 KB |
Output is correct |
17 |
Correct |
9 ms |
64092 KB |
Output is correct |
18 |
Correct |
9 ms |
64116 KB |
Output is correct |
19 |
Correct |
8 ms |
64132 KB |
Output is correct |
20 |
Correct |
9 ms |
64092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
64092 KB |
Output is correct |
2 |
Correct |
9 ms |
64088 KB |
Output is correct |
3 |
Correct |
9 ms |
64092 KB |
Output is correct |
4 |
Correct |
8 ms |
64096 KB |
Output is correct |
5 |
Correct |
9 ms |
64092 KB |
Output is correct |
6 |
Correct |
9 ms |
64092 KB |
Output is correct |
7 |
Correct |
9 ms |
64092 KB |
Output is correct |
8 |
Correct |
9 ms |
64176 KB |
Output is correct |
9 |
Correct |
10 ms |
64140 KB |
Output is correct |
10 |
Correct |
10 ms |
64092 KB |
Output is correct |
11 |
Correct |
9 ms |
64092 KB |
Output is correct |
12 |
Correct |
8 ms |
64088 KB |
Output is correct |
13 |
Correct |
9 ms |
64088 KB |
Output is correct |
14 |
Correct |
9 ms |
64088 KB |
Output is correct |
15 |
Correct |
9 ms |
64092 KB |
Output is correct |
16 |
Correct |
9 ms |
64088 KB |
Output is correct |
17 |
Correct |
9 ms |
64092 KB |
Output is correct |
18 |
Correct |
9 ms |
64116 KB |
Output is correct |
19 |
Correct |
8 ms |
64132 KB |
Output is correct |
20 |
Correct |
9 ms |
64092 KB |
Output is correct |
21 |
Correct |
13 ms |
64092 KB |
Output is correct |
22 |
Correct |
16 ms |
64092 KB |
Output is correct |
23 |
Correct |
15 ms |
64092 KB |
Output is correct |
24 |
Correct |
14 ms |
64092 KB |
Output is correct |
25 |
Correct |
15 ms |
64092 KB |
Output is correct |
26 |
Correct |
12 ms |
64092 KB |
Output is correct |
27 |
Correct |
14 ms |
64092 KB |
Output is correct |
28 |
Correct |
10 ms |
64088 KB |
Output is correct |
29 |
Correct |
11 ms |
64212 KB |
Output is correct |
30 |
Correct |
9 ms |
64092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
65364 KB |
Output is correct |
2 |
Correct |
90 ms |
65312 KB |
Output is correct |
3 |
Correct |
93 ms |
65620 KB |
Output is correct |
4 |
Correct |
94 ms |
65364 KB |
Output is correct |
5 |
Correct |
89 ms |
65360 KB |
Output is correct |
6 |
Correct |
86 ms |
65444 KB |
Output is correct |
7 |
Correct |
97 ms |
65388 KB |
Output is correct |
8 |
Correct |
90 ms |
65364 KB |
Output is correct |
9 |
Correct |
87 ms |
65500 KB |
Output is correct |
10 |
Correct |
96 ms |
65488 KB |
Output is correct |
11 |
Correct |
53 ms |
65364 KB |
Output is correct |
12 |
Correct |
65 ms |
65360 KB |
Output is correct |
13 |
Correct |
50 ms |
65364 KB |
Output is correct |
14 |
Correct |
63 ms |
66592 KB |
Output is correct |
15 |
Correct |
91 ms |
68224 KB |
Output is correct |
16 |
Correct |
51 ms |
66540 KB |
Output is correct |
17 |
Correct |
51 ms |
66640 KB |
Output is correct |
18 |
Correct |
102 ms |
68436 KB |
Output is correct |
19 |
Correct |
88 ms |
68176 KB |
Output is correct |
20 |
Correct |
50 ms |
66640 KB |
Output is correct |
21 |
Incorrect |
97 ms |
67732 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |