#include using namespace std; int t, n; long long f[2010][2010]; int a[2010], b[2010]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) scanf("%d", &b[i]); memset(f, 0x3f, sizeof f); f[0][0] = 0; long long sum = 0; for (int i = 1; i <= n; ++i) { sum += b[i]; for (int j = 0; j <= n; ++j) { f[i][j] = min(f[i][j], f[i - 1][j]); if (j && f[i - 1][j - 1] + a[i] <= sum) f[i][j] = min(f[i][j], f[i - 1][j - 1] + a[i]); } } int ans = 0; for (int i = 1; i <= n; ++i) if (f[n][i] <= sum) ans = i; printf("%d\n", ans); } }