#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;
suf[n]=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=-inf;
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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Partially correct |
1 ms |
460 KB |
Partially correct |
2 |
Incorrect |
241 ms |
596532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
460 KB |
Partially correct |
2 |
Incorrect |
241 ms |
596532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |