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;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=5e5+10;
const ll inf=2e18;
ll ma[301],dp[M][301],n,k,a[M],b[M],suf[M];
int main() {
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
ll sum=0;
for(int i=n-1;i>=0;i--) {
sum-=a[i];
dp[i][0]=sum;
for(int j=1;j<=k;j++)
dp[i][j]=-inf;
}
for(int i=n-1;i>=0;i--)
suf[i]=suf[i+1]+a[i];
sum=0;
for(int i=0;i<=k;i++)
ma[i]=-inf;
ma[0]=-suf[0];
for(int i=0;i<n;i++) {
for(int j=k;j>=1;j--) {
dp[i][j]=max(dp[i][j],ma[j-1]+b[i]);
ma[j]=max(ma[j],dp[i][j]);
}
}
ll ans=-1;
for(int i=0;i<n;i++)
ans=max(ans,dp[i][k]+suf[i+1]);
cout<<ans<<'\n';
for(int i=0;i<n;i++)
cout<<0;
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... |