#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
bool IsGood(const int64 alpha, const vector<int>& a, const vector<int>& b) {
  const int n = a.size();
  int64 total_negative = 0;
  vector<int> first;
  vector<pair<int, int64>> second;
  for (int i = 0; i < n; ++i) {
    const int64 cost = a[i] * 1000LL - b[i] * alpha;
    if (cost < 0) {
      total_negative -= cost;
      first.push_back(a[i]);
    } else {
      second.emplace_back(a[i], cost);
    }
  }
  sort(first.begin(), first.end());
  sort(second.begin(), second.end(),
       [](const pair<int, int64>& left, const pair<int, int64>& right) {
         return left.first < right.first;
       });
  vector<vector<int64>> ans(first.size() + 1, vector<int64>(second.size() + 1));
  for (size_t i = 0; i <= first.size(); ++i) {
    ans[i][0] = 0;
    for (size_t j = 1; j <= second.size(); ++j) {
      const int j2 =
          ((j >= 2 && second[j - 1].first > second[j - 2].first) ? j - 2
                                                                 : j - 1);
      ans[i][j] = ans[i][j2] + second[j - 1].second;
      if (i > 0 && first[i - 1] > second[j - 1].first) {
        ans[i][j] = min(ans[i][j], ans[i - 1][j - 1]);
      }
    }
  }
  return ans[first.size()][second.size()] <= total_negative;
}
void solve() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  int64 low = 0;
  int64 hi = 1e12;
  while (low + 1 < hi) {
    const int64 middle = (low + hi) / 2;
    if (IsGood(middle, a, b)) {
      hi = middle;
    } else {
      low = middle;
    }
  }
  cout << hi << "\n";
}
int main() {
  solve();
  return 0;
}
