#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
long long pre[200005];
long long sum(int a,int b) {
return pre[b] - pre[a-1];
}
set<pair<int,int> > st;
set<pair<int,int> > :: iterator it;
multiset<long long> mset;
multiset<long long> :: iterator it2;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
pre[0] = 0;
long long n,x;
cin>>n;
for(int i=1 ;i<=n;i++) {
cin>>x;
pre[i] = pre[i-1] + x;
}
st.insert(make_pair(1,n));
mset.insert(sum(1,n));
pair<int,int> p,p1,p2;
for(int i=0;i<n;i++) {
cin>>x;
it = st.upper_bound(make_pair(x,1e9));
it -- ;
p = *it;
//cout<<"df";
st.erase(it);
mset.erase(sum(p.first,p.second));
//if(p.first == p.second) continue;
//p1 = make_pair(p.first,x-1);
//p2 = make_pair(x+1,p.second);
//if(x-1>=p.first) {
if(x-1 >= p.first)
st.insert(make_pair(p.first,x-1));
mset.insert(sum(p.first,x-1));
//} else mset.insert(0);
//if(x+1<=p.second) {
if(x+1 <= p.second)
st.insert(make_pair(x+1,p.second));
mset.insert(sum(x+1,p.second));
//}// else mset.insert(0);
it2 = mset.end();
it2 -- ;
cout<< *it2<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBNQVggMTAwMDAwMDAwNwoKbG9uZyBsb25nIHByZVsyMDAwMDVdOwpsb25nIGxvbmcgc3VtKGludCBhLGludCBiKSB7CgkKCXJldHVybiBwcmVbYl0gLSBwcmVbYS0xXTsKfQoKc2V0PHBhaXI8aW50LGludD4gPiBzdDsKCnNldDxwYWlyPGludCxpbnQ+ID4gOjogaXRlcmF0b3IgaXQ7Cm11bHRpc2V0PGxvbmcgbG9uZz4gbXNldDsKbXVsdGlzZXQ8bG9uZyBsb25nPiA6OiBpdGVyYXRvciBpdDI7CmludCBtYWluKCkgewoJCglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUo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