#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
struct Node {
  int l, r;
  long long ms, ls, rs;
  int mark;
} node[maxn * 8];
long long num[maxn];
void build(int k, int l, int r) {
  node[k].l = l;
  node[k].r = r;
  node[k].mark = 1;
  if (l == r) {
    node[k].ls = node[k].ms = node[k].rs = num[l];
    return;
  }
  int mid = (node[k].l + node[k].r) >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  node[k].ls = node[k].ms = node[k].rs =
      (node[k << 1].ms + node[k << 1 | 1].ms);
}
void update(int k, int l, int r) {
  if (node[k].l == l && node[k].r == r) {
    node[k].ls = node[k].ms = node[k].rs = 0;
    node[k].mark = 0;
    return;
  }
  int mid = (node[k].l + node[k].r) >> 1;
  if (r <= mid)
    update(k << 1, l, r);
  else
    update(k << 1 | 1, l, r);
  node[k].ls = node[k << 1].ls;
  if (node[k << 1].mark) node[k].ls += node[k << 1 | 1].ls;
  node[k].rs = node[k << 1 | 1].rs;
  if (node[k << 1 | 1].mark) node[k].rs += node[k << 1].rs;
  node[k].ms = max(node[k << 1].ms, node[k << 1 | 1].ms);
  node[k].ms = max(node[k].ms, node[k << 1].rs + node[k << 1 | 1].ls);
  if (!node[k << 1].mark || !node[k << 1 | 1].mark) node[k].mark = 0;
}
int main() {
  int i, j, n, x;
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) scanf("%I64d", &num[i]);
    build(1, 1, n);
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      update(1, x, x);
      printf("%I64d\n", node[1].ms);
    }
  }
  return 0;
}
