# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1093775 |
2024-09-27T11:44:17 Z |
muhammad |
Feast (NOI19_feast) |
C++17 |
|
194 ms |
262144 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N + 1);
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
// Initialize the DP arrays
vector<vector<long long>> f(N + 1, vector<long long>(K + 1, LLONG_MIN));
vector<vector<long long>> g(N + 1, vector<long long>(K + 1, LLONG_MIN));
// Base case
f[0][0] = 0;
g[0][0] = 0;
// Fill DP tables
for (int n = 1; n <= N; ++n) {
for (int k = 0; k <= K; ++k) {
// Calculate g(n, k)
if (k > 0) {
g[n][k] = max(g[n - 1][k], f[n - 1][k - 1]) + A[n];
}
// Calculate f(n, k)
f[n][k] = max(f[n - 1][k], g[n][k]);
}
}
// The answer is f(N, K), i.e., the maximum sum of K subarrays in the first N integers
cout << f[N][K] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
194 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
34648 KB |
Output is correct |
2 |
Correct |
64 ms |
35412 KB |
Output is correct |
3 |
Correct |
66 ms |
34716 KB |
Output is correct |
4 |
Runtime error |
151 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
36944 KB |
Output is correct |
2 |
Correct |
113 ms |
36504 KB |
Output is correct |
3 |
Correct |
107 ms |
36944 KB |
Output is correct |
4 |
Correct |
103 ms |
36436 KB |
Output is correct |
5 |
Correct |
99 ms |
36952 KB |
Output is correct |
6 |
Correct |
108 ms |
37204 KB |
Output is correct |
7 |
Correct |
104 ms |
37304 KB |
Output is correct |
8 |
Correct |
102 ms |
36904 KB |
Output is correct |
9 |
Correct |
106 ms |
37456 KB |
Output is correct |
10 |
Correct |
106 ms |
37204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
194 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |