#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3000+10;
int n;
int a[maxn],c[maxn];
int pre[maxn],aft[maxn];
int ans=1e18;
//bool f;
signed main()
{
// freopen("A.in","r",stdin);
// freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
pre[i]=1e18;
aft[i]=1e18;
}
for(int i=1;i<=n;i++)
{
cin>>c[i];
}
for(int i=1;i<=n;i++)
{
for(int j=i-1;j>=1;j--)
{
if(a[j]<a[i])
{
pre[i]=min(pre[i],c[j]);
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i]<a[j])
{
aft[i]=min(aft[i],c[j]);
}
}
}
for(int i=2;i<n;i++)
{
ans=min(ans,c[i]+pre[i]+aft[i]);
}
if(ans>=1e18)cout<<-1;
else cout<<ans;
return 0;
}
1
这是 2025年10月28日 存档的第 3 版,不是当前版本。查看当前版本