#include <bits/stdc++.h>
using namespace std;
const long long int INF = 10000000000L;
const int MAX_N = 50;
const int MAX_PROCESSORS = 5000;
struct Task {
  int power, processorsSum;
  vector<int> processors;
  Task(int pow, int processor) : power(pow), processorsSum(processor) {
    processors.push_back(processor);
  }
};
int N;
double answer;
vector<Task> tasks;
map<int, int> powerToIndex;
int cpuSum;
void input() {
  int powers[MAX_N], cpus[MAX_N], indices[MAX_N];
  long long int powerSum = 0L;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> powers[i];
    powerSum += powers[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> cpus[i];
    cpuSum += cpus[i];
  }
  answer = (double)powerSum / cpuSum;
  for (int i = 0; i < N; ++i) {
    indices[i] = i;
  }
  sort(indices, indices + N,
       [powers](int a, int b) -> bool { return powers[a] > powers[b]; });
  int previousPower = -1;
  for (int i = 0; i < N; ++i) {
    int index = indices[i];
    if (powers[index] == previousPower) {
      tasks[tasks.size() - 1].processors.push_back(cpus[index]);
      tasks[tasks.size() - 1].processorsSum += cpus[index];
    } else {
      powerToIndex[powers[index]] = powerToIndex.size();
      tasks.push_back(Task(powers[index], cpus[index]));
    }
    previousPower = powers[index];
  }
  for (auto& task : tasks) {
    sort(task.processors.begin(), task.processors.end());
  }
}
long long int T[MAX_N][MAX_N + 1][MAX_PROCESSORS + 1];
void initDp() {
  for (int i = 0; i < tasks.size(); ++i) {
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= cpuSum; ++k) {
        T[i][j][k] = INF;
      }
    }
  }
}
void dp() {
  initDp();
  T[0][tasks[0].processors.size()][tasks[0].processorsSum] =
      tasks[0].power * tasks[0].processors.size();
  for (int i = 1; i < tasks.size(); ++i) {
    for (int j = 0;; ++j) {
      int jj = j + tasks[i].processors.size();
      if (jj > N) {
        break;
      }
      for (int k = 0;; ++k) {
        int kk = k + tasks[i].processorsSum;
        if (kk > cpuSum) {
          break;
        }
        T[i][jj][kk] = min(
            T[i][jj][kk],
            T[i - 1][j][k] + tasks[i].power * (int)tasks[i].processors.size());
      }
    }
    int curSum = 0;
    for (int p = 1; p <= tasks[i].processors.size(); ++p) {
      curSum += tasks[i].processors[p - 1];
      for (int j = 0; j <= N; ++j) {
        int jj = j + tasks[i].processors.size() - p - p;
        if (jj > N) {
          break;
        }
        if (jj < 0) {
          continue;
        }
        for (int k = 0;; ++k) {
          int kk = k + tasks[i].processorsSum - curSum;
          if (kk > cpuSum) {
            break;
          }
          T[i][jj][kk] =
              min(T[i][jj][kk],
                  T[i - 1][j][k] +
                      tasks[i].power * ((int)tasks[i].processors.size() - p));
        }
      }
    }
  }
  for (int j = 0; j <= N; ++j) {
    for (int k = 0; k <= cpuSum; ++k) {
      answer = min(answer, (double)T[tasks.size() - 1][j][k] / k);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  input();
  dp();
  cout.precision(0);
  cout << fixed << ceil(answer * 1000.) << '\n';
  return 0;
}
