#include #include #include #include #include #include using namespace std; #define FOR(i, l, r) for(int i = l; i <= r; i++) #define REP(i, r, l) for(int i = r; i >= l; i--) typedef long long ll; double eps = 1e-6; const int maxn = 100050; const int mod = 1e9 + 7; int d[maxn], h[maxn]; int n; double Upper(double ht) { double s = 0; FOR(i, 0, n-1) { if(ht > h[i]) continue; else s += (h[i] - ht) * (1 - ht / h[i]) * (1 - ht / h[i]) * d[i] * d[i]; } return s; } int main() { int cas; scanf("%d", &cas); while(cas--) { scanf("%d", &n); int R = -1; FOR(i, 0, n-1) scanf("%d", &h[i]), R = max(R, h[i]); FOR(i, 0, n-1) scanf("%d", &d[i]); ll sum = 0; FOR(i, 0, n-1) sum += 1ll * d[i] * d[i] * h[i]; double r = R, l = 0; while(l + eps < r){ double mid = (l + r)/2; if(Upper(mid) * 2 > sum) l = mid; else r = mid; } double ans = 0, ht = l; printf("%.0f\n", floor(l)); // FOR(i, 0, n-1) // { // if(h[i] < l) continue; // else ans += (1 - ht / h[i]) * (1 - ht / h[i]) * d[i] * d[i]; // } // printf("%.0f\n", ans); } return 0; }