#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(int x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- class CompareDist { public: bool operator()(pair n1,pair n2) { if(n1.first == n2.first) { return n1.second > n2.second; } return n1.first>n2.first; } }; int main() { int n; cin >> n; vector a(n); FOR(x, n) { cin >> a[x]; } vector b(n); FOR(x, n) { cin >> b[x]; } priority_queue, vector>,CompareDist> source; FOR(y, n) { source.push(make_pair(a[y], 0)); } int minValue = 1000000000; FOR(s, n) { int maxValue = 0; priority_queue, vector>,CompareDist> copy = source; FOR(x, n) { int index = (s + x) % n; auto top = copy.top(); copy.pop(); auto next = make_pair(top.first + b[index]/2, top.second+1); maxValue = max(maxValue, next.second); copy.push(next); } //cout << s << "," << maxValue << endl; if(minValue > maxValue) { minValue = maxValue; } } cout << minValue << endl; return 0; }