#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T> const& v) {
  s << '{';
  for (int i = 0; i < int(v.size()); i++) s << (i ? "," : "") << v[i];
  return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T> const& p) {
  return s << '(' << p.first << ',' << p.second << ')';
}
struct Dp {
  long long dp[51][5001];
  Dp() {
    for (int i = 0; i < int(51); i++)
      for (int j = 0; j < int(5001); j++) dp[i][j] = LLONG_MAX;
  }
};
int main() {
  int N;
  scanf("%d", &N);
  vector<pair<int, int> > pts(N);
  for (int n = 0; n < int(N); n++) scanf("%d", &pts[n].first);
  for (int n = 0; n < int(N); n++) scanf("%d", &pts[n].second);
  sort(begin(pts), end(pts), greater<pair<int, int> >());
  Dp dp;
  dp.dp[0][0] = 0;
  vector<pair<int, int> > ap;
  for (int n = 0; n < int(N + 1); n++) {
    if (n == N || (n > 0 && pts[n].first != pts[n - 1].first)) {
      Dp newdp;
      for (int t = 0; t < int(51); t++)
        for (int d = 0; d < int(5001); d++)
          if (dp.dp[t][d] != LLONG_MAX) {
            int b = n - ((int)(ap).size()) - t;
            for (int addB = 0; addB < int(min(((int)(ap).size()), t - b) + 1);
                 addB++) {
              long long addT = ((int)(ap).size()) - addB;
              long long newN = dp.dp[t][d] + addT * ap[0].first, newD = d;
              for (int i = 0; i < int(addT); i++) newD += ap[i].second;
              long long& v = newdp.dp[t + addT][newD];
              v = min(v, newN);
            }
          }
      ap.clear();
      dp = newdp;
    }
    if (n < N) ap.push_back(pts[n]);
  }
  long long ans = LLONG_MAX;
  for (int i = 0; i < int(51); i++)
    for (int j = 0; j < int(5001); j++) {
      long long v = dp.dp[i][j];
      if (v == LLONG_MAX) continue;
      ans = min(ans, (v * 1000LL + j - 1) / j);
    }
  printf("%lld\n", ans);
}
