# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
971497 |
2024-04-28T16:48:03 Z |
njoop |
K blocks (IZhO14_blocks) |
C++14 |
|
44 ms |
86940 KB |
#include <bits/stdc++.h>
using namespace std;
int n, k, arr[100010];
pair<int, int> dp[100010][110];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=0; i<100010; i++) {
for(int j=0; j<110; j++) {
dp[i][j] = {1e9, 1e9};
}
}
dp[1][1] = {arr[1], arr[1]};
for(int i=1; i<n; i++) {
for(int j=1; j<=k; j++) {
if(j > i) continue;
if(dp[i+1][j+1].first > dp[i][j].first + arr[i+1]) {
dp[i+1][j+1].first = dp[i][j].first + arr[i+1];
dp[i+1][j+1].second = arr[i+1];
}
if(dp[i+1][j].first > dp[i][j].first) {
dp[i+1][j].first = dp[i][j].first;
if(dp[i][j].second < arr[i+1]) {
dp[i+1][j].first += arr[i+1] - dp[i][j].second;
dp[i][j].second = arr[i+1];
}
}
}
}
cout << dp[n][k].first;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
86612 KB |
Output is correct |
2 |
Correct |
33 ms |
86724 KB |
Output is correct |
3 |
Correct |
30 ms |
86772 KB |
Output is correct |
4 |
Correct |
30 ms |
86620 KB |
Output is correct |
5 |
Correct |
33 ms |
86736 KB |
Output is correct |
6 |
Correct |
32 ms |
86612 KB |
Output is correct |
7 |
Correct |
36 ms |
86612 KB |
Output is correct |
8 |
Correct |
33 ms |
86684 KB |
Output is correct |
9 |
Correct |
30 ms |
86612 KB |
Output is correct |
10 |
Correct |
30 ms |
86648 KB |
Output is correct |
11 |
Incorrect |
34 ms |
86608 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
86604 KB |
Output is correct |
2 |
Correct |
32 ms |
86940 KB |
Output is correct |
3 |
Correct |
31 ms |
86680 KB |
Output is correct |
4 |
Correct |
30 ms |
86808 KB |
Output is correct |
5 |
Correct |
36 ms |
86624 KB |
Output is correct |
6 |
Correct |
30 ms |
86896 KB |
Output is correct |
7 |
Correct |
29 ms |
86724 KB |
Output is correct |
8 |
Correct |
30 ms |
86612 KB |
Output is correct |
9 |
Correct |
37 ms |
86576 KB |
Output is correct |
10 |
Correct |
31 ms |
86556 KB |
Output is correct |
11 |
Incorrect |
29 ms |
86624 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
86612 KB |
Output is correct |
2 |
Correct |
33 ms |
86724 KB |
Output is correct |
3 |
Correct |
30 ms |
86772 KB |
Output is correct |
4 |
Correct |
30 ms |
86620 KB |
Output is correct |
5 |
Correct |
33 ms |
86736 KB |
Output is correct |
6 |
Correct |
32 ms |
86612 KB |
Output is correct |
7 |
Correct |
36 ms |
86612 KB |
Output is correct |
8 |
Correct |
33 ms |
86684 KB |
Output is correct |
9 |
Correct |
30 ms |
86612 KB |
Output is correct |
10 |
Correct |
30 ms |
86648 KB |
Output is correct |
11 |
Incorrect |
34 ms |
86608 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
86612 KB |
Output is correct |
2 |
Correct |
33 ms |
86724 KB |
Output is correct |
3 |
Correct |
30 ms |
86772 KB |
Output is correct |
4 |
Correct |
30 ms |
86620 KB |
Output is correct |
5 |
Correct |
33 ms |
86736 KB |
Output is correct |
6 |
Correct |
32 ms |
86612 KB |
Output is correct |
7 |
Correct |
36 ms |
86612 KB |
Output is correct |
8 |
Correct |
33 ms |
86684 KB |
Output is correct |
9 |
Correct |
30 ms |
86612 KB |
Output is correct |
10 |
Correct |
30 ms |
86648 KB |
Output is correct |
11 |
Incorrect |
34 ms |
86608 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |