#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; void testcase(){ int N; cin >> N; vector> A(N); rep(i,N) cin >> A[i].first; rep(i,N) cin >> A[i].second; sort(A.rbegin(), A.rend()); vector dp(1000100); rep(i,dp.size()) dp[i] = i; for(auto [a,b] : A) chmax(dp[a], dp[a+b]); cout << dp[1] << "\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }