#include <bits/stdc++.h>
using namespace std;
struct rec {
  long long a;
  int b;
} num[51];
int i, j, m, n, b[51], k, l, maxsum;
long long dp[2][52][52][5001], a[51], inf, ans, temp, g[2][52][5001];
long long getmin(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long divup(long long a, long long b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
bool cmp(rec a, rec b) {
  if (a.a > b.a)
    return true;
  else
    return false;
}
int main() {
  maxsum = 5000;
  inf = 1000000000000000000;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &num[i].a);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &num[i].b);
  }
  sort(num + 1, num + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    a[i] = num[i].a;
    b[i] = num[i].b;
  }
  for (i = 0; i <= 1; i++) {
    for (j = 0; j <= n + 1; j++) {
      for (l = 0; l <= maxsum; l++) {
        g[i][j][l] = inf;
      }
      for (k = 0; k <= n + 1; k++) {
        for (l = 0; l <= maxsum; l++) {
          dp[i][j][k][l] = inf;
        }
      }
    }
  }
  g[0][0][0] = 0;
  dp[0][0][0][0] = 0;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= i; j++) {
      for (l = 0; l <= maxsum; l++) {
        g[i & 1][j][l] = inf;
      }
      for (k = 0; k <= j; k++) {
        for (l = 0; l <= maxsum; l++) {
          if (a[i] == a[i - 1]) {
            dp[i & 1][j][k][l] = dp[(i + 1) & 1][j + 1][k][l];
            if ((j) && (k) && (l >= b[i])) {
              dp[i & 1][j][k][l] =
                  getmin(dp[i & 1][j][k][l],
                         dp[(i + 1) & 1][j - 1][k - 1][l - b[i]] + a[i]);
            }
          } else {
            if (k > 1)
              dp[i & 1][j][k][l] = inf;
            else if (k == 0) {
              dp[i & 1][j][k][l] = g[(i + 1) & 1][j + 1][l];
            } else {
              if ((j) && (l >= b[i]))
                dp[i & 1][j][k][l] = g[(i + 1) & 1][j - 1][l - b[i]] + a[i];
              else
                dp[i & 1][j][k][l] = inf;
            }
          }
          if (dp[i & 1][j][k][l] < g[i & 1][j][l])
            g[i & 1][j][l] = dp[i & 1][j][k][l];
        }
      }
    }
  }
  ans = inf;
  for (j = 0; j <= n; j++) {
    for (k = 0; k <= j; k++) {
      for (l = 1; l <= maxsum; l++) {
        temp = divup(dp[n & 1][j][k][l] * 1000, l);
        if (temp < ans) {
          ans = temp;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
