#include #include struct mon { struct mon* next; int level; int count; }; int cmp(const void* a, const void* b) { return (*(int*)a - *(int*)b); } struct mon *List = 0; struct mon *ListPool = 0; void list_init(int N, int *A) { if (ListPool == 0) { qsort(A, N, sizeof(int), cmp); ListPool = (struct mon*)malloc(sizeof(struct mon)*N); } List = ListPool; int i; for (i=0; inext; a->next = 0; return a; } void list_in(struct mon *a) { struct mon *l1 = 0; struct mon *l = List; while (l!=0) { if (a->level < l->level) { break; } else if (a->level == l->level) { if (a->count <= l->count) { break; } else { l1 = l; } } else { l1 = l; } l = l->next; } if (l1 == 0) { a->next = List; List = a; } else { a->next = l1->next; l1->next = a; } return; } int main() { int N; scanf("%d", &N); int *A = (int*)malloc(sizeof(int)*N); int *B = (int*)malloc(sizeof(int)*N); int i; for (i=0; ilevel += B[(i+j)%N]/2; a->count++; cnt = a->count; list_in(a); if (max < cnt) max = cnt; if (min <= max) goto NEXT; } if (max < min) { min = max; } NEXT: max = 0; list_init(N, A); } printf("%d\n", min); return 0; }