#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef std::string str;
#define sei set<int>
#define sell set<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vld vector<ld>
#define vstr vector<str>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(v) v.begin(),v.end()
#define foa(i,v) for(auto i : v)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define deb(x)  cerr << #x << " = " << x << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define OK order_of_key
#define FO find_by_order
#define nmax 51
const ld PI = 3.141592653589793238462643383279;
const ll inf = std::numeric_limits<ll>::max();
const int infint = std::numeric_limits<int>::max();
const ll mod = 1e9+7;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll dp[nmax][nmax],odp[nmax][nmax];
ll q[nmax],p[nmax];
ll n,o[nmax];

bool check(ll lim) {
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	ll last = -1;
	for (int j = n - 1; j >= 0; --j) {
		int i = o[j];
		if (p[i] != last) {
			memcpy(odp, dp, sizeof dp);
			memset(dp, 63, sizeof dp);
			for (int x = 0; x < n; ++x)
				for (int y = 0; x + y < n; ++y)
					dp[x + y][0] = min(dp[x + y][0], odp[x][y]);
			last = p[i];
		}
		memcpy(odp, dp, sizeof dp);
		memset(dp, 63, sizeof dp);
		ll val = p[i] - q[i] * lim;
		for (int p0 = 0; p0 <= n; ++p0) {
			for (int p1 = 0; p1 <= n; ++p1) {
				dp[p0][p1 + 1] = min(dp[p0][p1 + 1], odp[p0][p1] + val);
			}
		}
		for (int p0 = 1; p0 <= n; ++p0) {
			for (int p1 = 0; p1 <= n; ++p1) {
				dp[p0 - 1][p1] = min(dp[p0 - 1][p1], odp[p0][p1]);
			}
		}
	}
	for (int j = 0; j < n; ++j)
		for (int i = 0; i < n; ++i)
			if (dp[j][i] <= 0)
				return 1;
	return 0;
}

int cmp(int x, int y) { return p[x] < p[y]; }

ll bis(ll l,ll r){
    if(l == r) return l;
    ll mid = (l+r)/2;
    if(check(mid)) return bis(l,mid);
    else return bis(mid+1,r);
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n;
    fo(i,0,n) cin >> p[i],p[i] *= 1000,o[i] = i;
    fo(i,0,n) cin >> q[i];
    sort(o,o+n,cmp);
    cout << bis(1,1e18);


    return 0;
}
