#include <bits/stdc++.h>
using namespace std;
int n, in;
vector<long long> a;
vector<int> b;
vector<pair<long long, int>> cur;
int main() {
  cin >> n;
  for (int i = 0; i < (n << 1); i++) {
    cin >> in;
    if (i < n)
      a.push_back(in);
    else
      b.push_back(in);
  }
  for (int i = 0; i < n; i++) a[i] *= 1000;
  for (int i = 0; i < n; i++) cur.push_back(make_pair(a[i], b[i]));
  long long lo = 0, hi = 1e12;
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    vector<pair<long long, long long>> c;
    for (int i = 0; i < n; i++) {
      c.push_back(make_pair(cur[i].first, (long long)cur[i].first -
                                              (long long)mid * cur[i].second));
    }
    sort(c.begin(), c.end());
    reverse(c.begin(), c.end());
    priority_queue<long long> jin;
    vector<long long> var;
    int cnt = 0, aux = 0;
    vector<long long> x;
    long long p = 0;
    long long res = 0;
    for (int i = 0; i < n; i++) {
      if (i > 0 && c[i].first != c[i - 1].first) {
        cnt += aux;
        aux = 0;
        for (auto j : var) jin.push(-j);
        var.clear();
      }
      if (c[i].second <= 0) {
        res += c[i].second;
        x.push_back(c[i].second);
        aux++;
        continue;
      }
      if (cnt >= i + 1 - cnt - aux) {
        var.push_back(c[i].second);
        continue;
      }
      if (jin.empty()) {
        res += c[i].second;
        x.push_back(c[i].second);
        aux++;
      } else {
        if (-c[i].second >= jin.top()) {
          res += c[i].second;
          x.push_back(c[i].second);
          aux++;
          continue;
        }
        res -= jin.top();
        x.push_back(-jin.top());
        jin.pop();
        var.push_back(c[i].second);
        cnt++;
      }
    }
    if (res <= 0)
      hi = mid;
    else
      lo = mid;
  }
  cout << hi << endl;
  return 0;
}
