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 ll long long
#define fi first
#define se second
#define ii pair<ll,ll>
const ll maxn=2e5+2;
int a[maxn];
ll dp[2002][2006];
ll ans;
int main(){
int n,k; cin>>n>>k;
for (int i=1;i<=n;++i) cin>>a[i];
for (int j=1;j<=k;++j){
for (int i=1;i<=n;++i){
dp[i][j]=max({dp[i-1][j]+a[i], dp[i-1][j-1]+a[i],dp[i][j],dp[i-1][j-1]});
//cout<<dp[i][j]<<" ";
ans=max(ans,dp[i][j]);
}
//cout<<endl;
}
cout<<ans<<endl;
}
# | 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... |