#include <bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
int n, vis[N];
pair<long long, long long> p[N], b[N];
priority_queue<long long, vector<long long>, greater<long long> > q;
template <typename T>
inline T read() {
  T x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * w;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first == b.first ? a.second > b.second : a.first > b.first;
}
bool check(long long mid) {
  for (int i = 1; i <= n; i++)
    b[i].first = p[i].first, b[i].second = p[i].first - mid * p[i].second,
    vis[i] = 0;
  sort(b + 1, b + n + 1, cmp);
  long long res = 0;
  for (int i = 1; i <= n; i++)
    if (b[i].second <= 0) vis[i] = 1, res += b[i].second;
  while (!q.empty()) q.pop();
  for (int cnt = 0, j = 1, i = 1; i <= n; i = j) {
    while (j <= n && b[i].first == b[j].first) j++;
    for (int k = i; k < j; k++)
      if (!vis[k]) {
        if (cnt)
          cnt--;
        else {
          if (q.size() && q.top() < b[k].second)
            res += q.top(), cnt++, q.pop();
          else
            vis[k] = 1, res += b[k].second;
        }
      }
    for (int k = i; k < j; k++)
      if (vis[k])
        cnt++;
      else
        q.push(b[k].second);
  }
  return res <= 0;
}
int main() {
  n = read<int>();
  for (int i = 1; i <= n; i++) p[i].first = read<long long>() * 1000;
  for (int i = 1; i <= n; i++) p[i].second = read<long long>();
  long long l = 1, r = 1000000000000, mid, ans = r;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
