#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; typedef vector VPII; #define X first #define Y second #define pb push_back #define bit(n) (1 << (n)) #define count(n) (__builtin_popcount(n)) #define countl(n) (__builtin_popcountll(n)) template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } const int MN = 100005; int A[MN], B[MN]; inline DB calc(DB x, DB h) { return x * x * h; } int main() { int n; int tn; for (cin >> tn; tn--; ) { scanf("%d", &n); DB en = 0, st = 0, mid, tot = 0; for (int i = 0; i < n; i++) scanf("%d", A + i), chkmax(en, 1.0 * A[i]); for (int i = 0; i < n; i++) scanf("%d", B + i); for (int i = 0; i < n; i++) { tot += calc(B[i], A[i]); } for (int i = 0; i < 50; i++) { mid = (st + en) / 2; DB sum = 0; for (int j = 0; j < n; j++) { if (mid < A[j]) sum += calc(B[j] * (A[j] - mid) / (DB)A[j], A[j] - mid); } if (sum < 0.5 * tot) en = mid; else st = mid; } printf("%d\n", int(mid)); } return 0; }