#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; typedef long double LD; #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define counti(x) (__builtin_popcount(x)) #define countl(x) (__builtin_popcountll(x)) #define rep(i, n) for (int (i) = 0; (i) < (int)(n); ++(i)) #define X first #define Y second template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } int get() { char c; while (c = getchar(), (c < '0' || c > '9') && (c != '-')); bool flag = (c == '-'); if (flag) c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); } return flag ? -x : x; } void output(int x) { if (x < 0) { putchar('-'); x = -x; } int len = 0, data[20]; while (x) { data[len++] = x % 10; x /= 10; } if (!len) data[len++] = 0; while (len--) putchar(data[len] + 48); putchar('\n'); } #define MX 123456 int a[MX], b[MX]; double s; int n; DB calc(DB mid) { DB res = 0; int i; for (i = 0; i < n; i++) { if (mid > a[i]) continue; res += 1. * b[i] * b[i] * (a[i] - mid) / a[i] * (a[i] - mid) * (a[i] - mid) / a[i]; } return res; } int main() { int Tcase; for (scanf("%d", &Tcase); Tcase--;) { scanf("%d", &n); s = 0; int i; for (i = 0; i < n; i++) scanf("%d", a + i); for (i = 0; i < n; i++) scanf("%d", b + i), s += 1.0 * b[i] * b[i] * a[i]; DB st = 0.0, en = 1000.0; for (i = 0; i < 20; i++) { DB mid = (st + en) / 2; DB s0 = calc(mid); if (s0 > s / 2) { st = mid; } else en = mid; } printf("%d\n", int(st + 1e-8)); } return 0; }