#include <iostream>
#include <vector>
#include <climits>
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 array with negative infinity
vector<long long> dp(K + 1, LLONG_MIN);
dp[0] = 0; // Base case: no plates and 0 people = 0 satisfaction
// Iterate through all plates
for (int i = 1; i <= N; ++i) {
// Start a temporary array for the next iteration
vector<long long> next_dp = dp;
// Maintain a variable to track the best value if starting a segment for person `j`
long long max_so_far = LLONG_MIN;
// Iterate over possible people in reverse to avoid overwriting our current dp values
for (int j = 1; j <= K; ++j) {
max_so_far = max(max_so_far, dp[j - 1]); // Find the best ending segment for `j-1`
next_dp[j] = max(next_dp[j], max_so_far + A[i]); // Update the current segment with the best value + current plate
}
dp = next_dp; // Update dp with our next_dp
}
// The final result is the maximum value for `K` people using up to N plates
cout << dp[K] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
4532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
111 ms |
1584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
4532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |