#include <iostream>usingnamespace std;
constint maxn=10000;
int n;
int a[maxn];
int b[maxn];
intf(int l,int r, int depth){
if(l>r)
return0;
int min=maxn,mink;
for (int i =0; i <=r; i++){
if (min>a[i]){
min=a[i];
mink=i;
}
}
int lres=f(l,mink-1,depth+1);
int rres=f(mink+1,r,depth+1);
return lres+rres+depth*b[mink];
}
intmain(){
cin>>n;
for (int i =0; i < n; i++)
cin>>a[i];
for (int i =0; i < n; i++)
cin>>b[i];
cout<<f(0,n-1,1)<<endl;
return0;
}
Time limit: 0
Quiz Summary
0 of 6 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.