/* -*- coding: utf-8 -*- * * 2999.cc: No.2999 Long Long Friedrice - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 2000; const int MAX_M = 1000000; /* typedef */ using vi = vector; /* global variables */ int as[MAX_N], bs[MAX_N]; vi nbrs[MAX_M]; bool ds[MAX_M]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--; for (int i = 0; i < n; i++) scanf("%d", bs + i); int m = 0; for (int i = 0; i < n; i++) { nbrs[as[i]].push_back(as[i] + bs[i]); m = max(m, as[i] + bs[i]); } ds[0] = true; int maxu = 0; for (int u = 0; u <= m; u++) if (ds[u]) { maxu = u; for (auto v: nbrs[u]) ds[v] = true; } printf("%d\n", maxu + 1); return 0; }