#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
double l, r, mid, v[100005], val[100005], dp[100005], DP[100005];
int i;
struct node {
  double a;
  int b;
} u[100005];
bool check(double x) {
  int i, las, k, len, j;
  double ret = 0, res = 1e14;
  memset(v, 0, sizeof(v));
  memset(dp, 0, sizeof(dp));
  memset(DP, 0, sizeof(DP));
  for (i = 1; i <= n; ++i) v[i] = -x * u[i].b + u[i].a;
  for (i = 1; i <= n; ++i)
    if (v[i] < 0) ret += v[i];
  for (i = 1; i <= n; ++i) dp[i] = 1e14;
  memset(val, 0, sizeof(val));
  for (i = las = 1; i <= n; ++i) {
    if (u[i].a != u[i + 1].a) {
      len = i - las + 1;
      for (j = 0; j <= i; ++j) {
        DP[j] = 1e14;
      }
      val[0] = 0;
      for (j = 1; j <= len; ++j) {
        val[j] = val[j - 1] + max(0.0, v[las + j - 1]);
      }
      for (j = 0; j <= len; ++j) val[j] = val[len] - val[j];
      for (j = 0; j < las; ++j) {
        for (k = 0; k <= min(j, len); ++k) {
          DP[j - k + len - k] = min(DP[j + len - k - k], dp[j] + val[k]);
        }
      }
      for (j = 0; j <= i; ++j) dp[j] = DP[j];
      las = i + 1;
    }
  }
  for (j = 0; j <= n; ++j) res = min(res, dp[j]);
  return (ret + res) < 0;
}
inline bool cmp(node aa, node bb) {
  return aa.a == bb.a ? aa.b < bb.b : aa.a > bb.a;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> u[i].a;
  for (i = 1; i <= n; ++i) cin >> u[i].b;
  sort(u + 1, u + n + 1, cmp);
  l = 0;
  r = 100000000;
  while (l < r - (1e-8)) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << (long long)(l * 1000 + 0.999999);
}
