#include #include #include #include #include using namespace std; #define LL long long const int MX = 2000 + 23; LL A[MX] ,B[MX] ,SB[MX] ,SA[MX]; int vis[MX]; void solve(){ int n; scanf("%d" ,&n); for(int i = 1 ; i <= n ; ++i) scanf("%lld" ,A + i) ,SA[i] = SA[i - 1] + A[i]; for(int i = 1 ; i <= n ; ++i) scanf("%lld" ,B + i) ,SB[i] = SB[i - 1] + B[i]; priority_queue Q; LL Time = 0, Ans = 0; B[n + 1] = 0 ,SB[n + 1] = 1e18; for(int i = 1 ; i <= n ; ++i){ Time += B[i]; if(Time >= A[i]){ Time -= A[i]; Ans += 1; Q.push(A[i]); } else if(!Q.empty() && Q.top() > A[i]){ Time += Q.top() - A[i]; Q.pop(); Q.push(A[i]); } } printf("%lld\n" ,Ans); } int main(){ int T; scanf("%d" ,&T); while(T--) solve(); return 0; }