이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#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];
}
// DP array initialized with a very small value (negative infinity)
vector<vector<long long>> dp(N + 1, vector<long long>(K + 1, LLONG_MIN));
dp[0][0] = 0; // Base case
// Iterate over each possible plate
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= K; ++j) {
// If not taking the i-th plate for the j-th person
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
// Iterate over the number of people (from 1 to K)
for (int j = 1; j <= K; ++j) {
// Keep track of the sum for the current segment ending at `i`
long long current_sum = 0;
// Iterate back from `i` to track the best sum ending at `i` for person `j`
for (int x = i; x > 0; --x) {
current_sum += A[x];
dp[i][j] = max(dp[i][j], dp[x - 1][j - 1] + current_sum);
}
}
}
cout << dp[N][K] << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |