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=6e3+10;
const ll inf=2e18;
ll n,k,a[M],b[M],pre[M],suf[M],pm[M],sm[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];
pre[0]=b[0];
for(int i=1;i<n;i++) {
pre[i]=pre[i-1]-b[i-1]+a[i-1]+b[i];
}
suf[0]=b[0]-a[0];
for(int i=1;i<n;i++) {
suf[i]=suf[i-1]-b[i-1]-a[i]+b[i];
}
pm[0]=pre[0];
for(int i=1;i<n;i++)
pm[i]=max(pre[i],pm[i-1]);
sm[n-1]=suf[n-1];
for(int i=n-2;i>=0;i--)
sm[i]=max(suf[i],sm[i+1]);
ll ans=0;
for(int i=0;i<n-1;i++) {
ans=max(ans,pre[i]+sm[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... |