#include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using namespace std; template using reversed_priority_queue = priority_queue, greater >; template void setmax(T & a, T const & b) { if (a < b) a = b; } template void setmin(T & a, T const & b) { if (b < a) a = b; } const int inf = 1e9+7; int main() { int n; cin >> n; vector as(n); repeat (i,n) cin >> as[i]; vector bs(n); repeat (i,n) cin >> bs[i]; int ans = inf; repeat (offset,n) { reversed_priority_queue > que; for (int a : as) que.emplace(a, 0); repeat (i,n) { int b = bs[(offset + i) % n]; int lvl, cnt; tie(lvl, cnt) = que.top(); que.pop(); que.emplace(lvl + b/2, cnt + 1); } int max_cnt = 0; while (not que.empty()) { int lvl, cnt; tie(lvl, cnt) = que.top(); que.pop(); setmax(max_cnt, cnt); } setmin(ans, max_cnt); } cout << ans << endl; return 0; }