#include #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) using namespace std; int main(){ int n; cin >> n; int a[n],b[n]; int a_sum=0; rep(i,n){ cin >> a[i]; } vector syukei(n); rep(i,n){ cin >> b[i]; syukei[b[i]] += a[i]; } reverse(syukei.begin(),syukei.end()); int last = syukei.back(); syukei.pop_back(); int MAX=last; for(int i= 0;i