#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=5100;
const ll INF=1e9+10;
#define dbg(x) cout<<" [ "<<#x<<" ] : "<<x<<endl;
#define F first
#define S second
#define all(v) v.begin(),v.end()
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
if(n==2){
if(c<l[0])
return d[0]+c+d[1];
return d[0]+l[0]+d[1];
}
vector<int> pref(MAXN+1,0);
for(int i=0;i<n-1;i++){
pref[i+1]=pref[i]+l[i];
}
vector<int> left(MAXN+1,0);
vector<int> right(MAXN+1,0);
//the idea is to use pref[i-1]+l[i] or d[i]
left[0]=d[0];
int first_node=0;
for(int i=1;i<n;i++){
if(d[i]>left[i-1]+l[i-1]) first_node=i;
left[i]=max(left[i-1]+l[i-1],d[i]);
}
int last_node=n-1;
right[n-1]=d[n-1];
for(int i=n-2;i>=0;i--){
if(d[i]>right[i+1]+l[i]) last_node=i;
right[i]=max(right[i+1]+l[i],d[i]);
}
vector<int> nodes;//nodes in the diameter
// cout<<first_node<<" "<<last_node<<endl;
int diameter=left[first_node]+right[first_node];
// cout<<diameter<<endl;
for(int i=first_node;i<=last_node;i++){
for(int j=i+1;j<=last_node;j++){
int express=left[i]+c+right[j];
int newdiameter=0;
for(int k=0;k<=j;k++){
newdiameter=max(newdiameter,abs(pref[j]-pref[k])+right[j]);
}
for(int k=n-1;k>=i;k--){
newdiameter=max(newdiameter,abs(pref[k]-pref[i])+left[i]);
}
// if(i==0&&j==7){
// cout<<pref[j]-
// }
// cout<<newdiameter<<" "<<express<<" "<<i<<" "<<j<<endl;
// if(newdiameter>express) continue;
diameter=min({max(newdiameter,express),diameter});
}
}
// cout<<c<<endl;
return diameter;
}
int main()
{
int n, c;
assert(2 == scanf("%d%d", &n, &c));
std::vector<int> l(n - 1);
std::vector<int> d(n);
for (int i = 0; i < n - 1; i++)
assert(1 == scanf("%d", &l[i]));
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &d[i]));
long long t = find_shortcut(n, l, d, c);
printf("%lld\n", t);
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccULP65e.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccVwJt3h.o:shortcut.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status