Submission #1072256

#TimeUsernameProblemLanguageResultExecution timeMemory
1072256edogawa_somethingTricks of the Trade (CEOI23_trade)C++17
0 / 100
241 ms596532 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...