This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k; cin >> n >> k;
int a[n], dp[2][k + 1], ans[2][k + 1]; for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++){
for(int j = 1; j <= k; j++){
dp[i & 1][j] = max(dp[(i + 1) & 1][j], ans[(i + 1) & 1][j - 1]) + a[i];
ans[i & 1][j] = max(ans[(i + 1) & 1][j], dp[i & 1][j]);
}
}
cout << ans[(n + 1) & 1][k] << '\n';
}
# | 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... |