codeforces地址:http://codeforces.com/contest/987/problem/C
从中间暴力
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3005;
const int inf = 0x3f3f3f3f;
LL a[N];
LL b[N];
LL c[N];
int main()
{
int n;
scanf("%d",&n);
for(int i = 0;i < n;++i)
scanf("%lld",&a[i]);
for(int i = 0;i < n;++i)
scanf("%lld",&b[i]);
for(int i = 0;i < n;++i)
{
LL Min = inf;
for(int j = 0;j < i;++j)
{
if(a[j] < a[i])
Min = min(Min,b[i] + b[j]);
}
c[i] = Min;
}
LL ans = inf;
for(int i = 0;i < n;++i)
{
LL Min = inf;
for(int j = i + 1;j < n;++j)
{
if(a[i] < a[j]){
Min = min(Min,c[i] + b[j]);
}
}
ans = min(ans,Min);
}
if(ans == inf){
printf("-1\n");
}
else{
printf("%lld\n",ans);
}
return 0;
}