#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int ddx[] = {-1, -2, 1, -2, 2, -1, 2, 1}, ddy[] = {-2, -1, -2, 1, -1, 2, 1, 2};
pair<long long, long long> p[50];
long long d[50][50][5001];
int n;
long long go(int N, int k, int c) {
  if (N == n) {
    if (c == 0) return 0;
    return 987654321987654321;
  }
  long long &ret = d[N][k][c];
  if (~ret) return ret;
  ret = 987654321987654321;
  int M = N;
  while (M < n && p[N].first == p[M].first) M++;
  M--;
  long long s = 0;
  int t = 0, cnt = 0;
  for (int(i) = (N); (i) <= (M); (i) += (1)) {
    s += p[i].first, t += p[i].second;
  }
  if (c >= t) {
    ret = min(ret, s + go(M + 1, k + M - N + 1, c - t));
  }
  for (int(i) = (M); (i) >= (N); (i) -= (1)) {
    cnt++;
    if (cnt > k) break;
    s -= p[i].first, t -= p[i].second;
    ret = min(ret, s + go(M + 1, k + M - N + 1 - 2 * cnt, c - t));
  }
  return ret;
}
int main() {
  memset((d), -1, sizeof(d));
  scanf("%d", &n);
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    scanf("%lld", &p[i].first);
    p[i].first *= 1000;
  }
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    scanf("%lld", &p[i].second);
  }
  if (n == 1) {
    return !printf("%lld\n", (p[0].first - 1) / p[0].second + 1);
  }
  sort(p, p + n);
  reverse(p, p + n);
  long long ans = 987654321987654321;
  for (int(i) = (1); (i) <= (5000); (i) += (1)) {
    long long t = go(0, 0, i);
    if (t != 987654321987654321) ans = min(ans, (t - 1) / i + 1);
  }
  printf("%lld\n", ans);
}
