#include "omp.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <random>
#include <bitset>
#include <unordered_set>
#include <cassert>
#include <list>


using namespace std;

typedef long long ll;
typedef long double ld;


const int sze = 50, M = 5e3 + 1, psze = 15;
const ll INF = 6e9 + 10;


ll dp[2][sze][M][sze];


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for (int i = 0; i < sze; ++i)
		for (int j = 0; j < M; ++j)
			for (int z = 0; z < sze; ++z)
				for (int cur = 0; cur <= 1; ++cur)
					dp[cur][i][j][z] = INF;//LL

	int n;
	cin >> n;
	vector<pair<int, int>> challengers(n);
	vector<int> pref(n);

	for (int i = 0; i < n; ++i)
		cin >> challengers[i].first;

	for (int i = 0; i < n; ++i)
		cin >> challengers[i].second;

	sort(challengers.begin(), challengers.end());


	pref[0] = challengers[0].second;
	for (int i = 1; i < n; ++i)
		pref[i] = pref[i - 1] + challengers[i].second;

	int cur = 0;
	for (int t = 0; t < n; ++t)
	{

		for (int i = 0; i <= t; ++i)
			for (int j = 0; j <= pref[t]; ++j)
				for (int z = 0; z <= t; ++z)
				{
					if (dp[cur][i][j][z] == INF)
						continue;

					dp[cur ^ 1][t][j + challengers[t].second][max(0, z + t - i - 1 - 1)] = min(dp[cur ^ 1][t][j + challengers[t].second][max(0, z + t - i - 1 - 1)], dp[cur][i][j][z] + challengers[t].first);
				}

		dp[cur ^ 1][t][challengers[t].second][max(0, t - 1)] = min(dp[cur ^ 1][t][challengers[t].second][max(0, t - 1)], ll(challengers[t].first));

		for (int i = 0; i <= t; ++i)
			for (int j = 0; j <= pref[t]; ++j)
				for (int z = 0; z <= t; ++z)
				{
					dp[cur ^ 1][i][j][z + 1] = min(dp[cur ^ 1][i][j][z + 1], dp[cur][i][j][z]);
					dp[cur][i][j][z] = INF;
				}
		cur ^= 1;
	}

	ll ans = INF;

	for (int j = 1; j < M; ++j)
		for (int cur = 0; cur <= 1; ++cur)
			if (dp[cur][n - 1][j][0] != INF)
				ans = min(ans, 1000LL * dp[cur][n - 1][j][0] / j);

	cout << ans;

	return 0;
}