#include #include #include typedef struct { uint64_t fst; uint64_t snd; } Pair; typedef Pair Key; int less_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd < b.snd : a.fst < b.fst; } int lt_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd <= b.snd : a.fst <= b.fst; } int greater_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd > b.snd : a.fst > b.fst; } int gt_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd >= b.snd : a.fst >= b.fst; } int equal_pair(Pair a, Pair b) { return a.fst == b.fst && a.snd == b.snd; } typedef struct SkewNode { Key key; struct SkewNode *left; struct SkewNode *right; } SNode, *SHeap; void swap_snode(SNode *x, SNode *y) { SNode tmp = *x; *x = *y; *y = tmp; } int top_sheap(SHeap h, Key *k) { if (h == NULL) return -1; *k = h->key; return 0; } SNode* merge_sheap(SHeap x, SHeap y) { if (x == NULL) return y; if (y == NULL) return x; if (greater_pair(x->key, y->key)) swap_snode(x, y); SNode *tmp = merge_sheap(x->right, y); x->right = x->left; x->left = tmp; return x; } SNode* push_sheap(SHeap h, Key k) { SNode *node; if ((node = (SNode *)malloc(sizeof(SNode))) == NULL) return h; node->key = k; node->left = node->right = NULL; return merge_sheap(h, node); } SNode* pop_sheap(SHeap h) { SNode *l = h->left; SNode *r = h->right; free(h); return merge_sheap(l, r); } void free_sheap(SHeap h) { if (h == NULL) return; if (h->left != NULL) free_sheap(h->left); if (h->right != NULL) free_sheap(h->right); free(h); } int main(void) { int N; scanf("%d", &N); int A[3030], B[3030]; for (int i = 0; i < N; i++) scanf("%d", &A[i]); for (int i = 0; i < N; i++) { scanf("%d", &B[i]); B[i + N] = B[i]; } int m = 1073741824; for (int i = 0; i < N; i++) { SHeap heap; int heap_size = 0; for (int j = 0; j < N; j++) { heap = push_sheap(heap, (Key){A[j], 0}); heap_size++; } for (int j = 0; j < N; j++) { SNode* x = pop_sheap(heap); heap = push_sheap(heap, (Key){x->key.fst + B[i + j] / 2, x->key.snd + 1}); } int tmp = 0; while (heap_size) { SNode* x = pop_sheap(heap); tmp = tmp > x->key.snd ? tmp : x->key.snd; heap_size--; } m = m < tmp ? m : tmp; free_sheap(heap); } printf("%d\n", m); return 0; }