#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 50;
long long p[N + 7];
long long c[N + 7];
long long wsp[N + 7];
long long dpn[N + 7][N + 7];
long long dpo[N + 7][N + 7];
long long dps[N + 7];
long long inf = 1e18;
bool check(long long s) {
  for (int i = 1; i <= n; ++i) {
    wsp[i] = s * c[i];
    wsp[i] -= p[i] * 1000;
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) dpo[i][j] = -inf;
  }
  dpo[1][0] = wsp[n];
  for (int x = n - 1; x >= 0; --x) {
    if (p[x] != p[x + 1]) {
      for (int i = 0; i <= n + 1; ++i) dps[i] = -inf;
      for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j) dps[i + j] = max(dps[i + j], dpo[i][j]);
      for (int i = 2; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) dpn[i][j] = -inf;
      }
      for (int j = 0; j <= n; ++j) {
        dpn[0][j] = dps[j + 1];
      }
      for (int j = 0; j <= n; ++j) {
        dpn[1][j] = wsp[x] + dps[j];
      }
    } else {
      for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
          dpn[i][j] = -inf;
          if (i > 0) dpn[i][j] = max(dpn[i][j], wsp[x] + dpo[i - 1][j]);
          if (j < n) dpn[i][j] = max(dpn[i][j], dpo[i][j + 1]);
        }
      }
    }
    for (int i = 0; i <= n; ++i)
      for (int j = 0; j <= n; ++j) dpo[i][j] = dpn[i][j];
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (dpo[i][j] >= 0) return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<pair<int, int>> pp(n);
  for (int i = 0; i < n; ++i) cin >> pp[i].first;
  for (int i = 0; i < n; ++i) cin >> pp[i].second;
  sort(pp.begin(), pp.end());
  for (int i = 1; i <= n; ++i) p[i] = pp[i - 1].first;
  for (int i = 1; i <= n; ++i) c[i] = pp[i - 1].second;
  long long p = 0;
  long long k = 1e11;
  k += 3;
  long long wynik = k;
  while (p <= k) {
    long long s = (p + k) / 2;
    if (check(s)) {
      k = s - 1;
      wynik = min(wynik, s);
    } else
      p = s + 1;
  }
  cout << wynik << endl;
  return 0;
}
