#include #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])) using namespace std; int main(){ int n; cin >> n; vector a(101),b(101); rep(i,n){ cin >> a[i]; } vector syukei(101); 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