#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() /* No.9 モンスターのレベル上げ 優先度付きキュー */ using namespace std; typedef long long ll; typedef pair P; int main() { ios_base::sync_with_stdio(0); int N; cin >> N; vector A(N, 0 ); rep (i, N ) cin >> A[i]; vector B(N, 0 ); rep (i, N ) cin >> B[i]; int res = 0; rep (i, N ){ priority_queue , greater > que; rep (j, N ) que.push (A[j]*10000 ); int start = i; for (int j = 0, k = start; j < N; j++, k = (k + 1 ) % N ){ int curr = que.top(); que.pop(); que.push (curr + B[k]/2 * 10000 + 1 ); } // end for int now = 0; while (!que.empty() ){ int curr = que.top(); que.pop(); now = max (now, curr%10000 ); } // end while res = max (res, now ); } // end rep cout << res << endl; return 0; }