#include <bits/stdc++.h>
using namespace std;
int const MAX = 55;
int const M = 5e3 + 41;
long long const INF = 1e18;
int n;
int a[MAX];
int b[MAX];
long long d[MAX][MAX][M];
vector<int> vid[MAX];
long long d1[2][MAX][M];
long long ans;
void clear(int id) {
  for (int i = 0; i <= MAX - 1; i++) {
    for (int j = 0; j <= M - 1; j++) {
      d1[id][i][j] = INF;
    }
  }
}
void calc(vector<int> &v) {
  for (int i = 0; i <= 1; i++) {
    clear(i);
  }
  d1[0][0][0] = 0;
  for (int i = 0; i <= (int)v.size() - 1; i++) {
    int id = v[i];
    clear(1);
    for (int o = 0; o <= MAX - 1; o++) {
      for (int j = 0; j <= M - 1; j++) {
        if (d1[0][o][j] == INF) continue;
        d1[1][o + 1][j + b[id]] =
            min(d1[1][o + 1][j + b[id]], d1[0][o][j] + a[id]);
        d1[1][o][j] = min(d1[1][o][j], d1[0][o][j]);
      }
    }
    memcpy(d1[0], d1[1], sizeof(d1[0]));
  }
}
void solve() {
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    v.push_back(-a[i]);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = 1; i <= n; i++) {
    int p = (int)(lower_bound(v.begin(), v.end(), -a[i]) - v.begin());
    vid[p].push_back(i);
  }
  for (int i = 0; i <= MAX - 1; i++) {
    for (int j = 0; j <= MAX - 1; j++) {
      for (int o = 0; o <= M - 1; o++) {
        d[i][j][o] = INF;
      }
    }
  }
  d[0][0][0] = 0;
  for (int i = 0; i <= (int)v.size() - 1; i++) {
    calc(vid[i]);
    for (int emp1 = 0; emp1 <= MAX - 1; emp1++) {
      for (int sumb1 = 0; sumb1 <= M - 1; sumb1++) {
        if (d[i][emp1][sumb1] == INF) continue;
        for (int emp2 = 0; emp2 <= (int)vid[i].size(); emp2++) {
          int two = (int)vid[i].size() - emp2;
          if (two > emp1) continue;
          for (int sumb2 = 0; sumb2 <= (int)vid[i].size() * 100; sumb2++) {
            if (d1[0][emp2][sumb2] == INF) continue;
            int newemp = emp1 + emp2 - two;
            int newsumb = sumb1 + sumb2;
            d[i + 1][newemp][newsumb] =
                min(d[i + 1][newemp][newsumb],
                    d[i][emp1][sumb1] + d1[0][emp2][sumb2]);
          }
        }
      }
    }
  }
  ans = INF;
  for (int i = 0; i <= MAX - 1; i++) {
    for (int j = 0; j <= M - 1; j++) {
      if (d[(int)v.size()][i][j] == INF) continue;
      int one = j;
      long long pans = (d[(int)v.size()][i][j] * 1000 + one - 1) / one;
      ans = min(ans, pans);
    }
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  solve();
  return 0;
}
