#include <bits/stdc++.h>
using namespace std;
const int BASE = 1000;
const double EPS = 1e-7;
const int MAX = 57;
const int INF = 1000000000;
long long dp[MAX][5007][MAX];
int main() {
  for (int i = (0); i < (MAX); ++i)
    for (int j = (0); j < (5007); ++j)
      for (int k = (0); k < (MAX); ++k) dp[i][j][k] = 1LL * INF * INF;
  dp[0][0][0] = 0;
  int n;
  cin >> n;
  vector<pair<int, int> > A(n);
  for (int i = (0); i < (n); ++i) {
    cin >> A[i].first;
  }
  for (int i = (0); i < (n); ++i) {
    cin >> A[i].second;
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int pos = 0;
  while (pos < n) {
    int add = 1;
    while (pos + add < n && A[pos + add].first == A[pos].first) ++add;
    for (int i = (0); i < (5001); ++i) {
      for (int j = (0); j < (pos + 1); ++j) {
        if (dp[pos][i][j] == 1LL * INF * INF) continue;
        int sum = 0;
        for (int k = (0); k < (add + 1); ++k) {
          if (j >= add - k) {
            dp[pos + add][i + sum][j - (add - k) + k] =
                min(dp[pos + add][i + sum][j - (add - k) + k],
                    dp[pos][i][j] + (long long)A[pos].first * k);
          }
          if (k < add) sum += A[pos + k].second;
        }
      }
    }
    pos = pos + add;
  }
  long long res = 1LL * INF * INF;
  for (int i = (1); i < (5001); ++i)
    for (int j = (0); j < (n + 1); ++j) {
      if (dp[n][i][j] == 1LL * INF * INF) continue;
      res = min(res, (dp[n][i][j] * 1000 + i - 1) / i);
    }
  cout << res << endl;
  return 0;
}
