#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int maxn = 10005; double h[maxn], a[maxn]; int T, n; double calc(int x) { double ans = 0; for(int i = 1; i <= n; i++) { if(x > h[i]) { ans += a[i] * a[i] * h[i]; } else { double y = (h[i] - x) / h[i]; ans += a[i] * a[i] * h[i] - a[i] * a[i] * h[i] * y * y * y; } } return ans; } int main() { //freopen("in.txt", "r", stdin); scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%lf", &h[i]); for(int i = 1; i <= n; i++) scanf("%lf", &a[i]); double V = 0; for(int i = 1; i <= n; i++) { V += a[i] * a[i] * h[i]; } double l = 0, r = 1000.0; for(int i = 0; i < 20; i++) { double mid = (l + r) / 2; if(calc(mid) * 2 < V) { l = mid; } else { r = mid; } } // printf("act = %.10f\n", l); printf("%d\n", (int)floor(l)); } return 0; }