#include using namespace std; #define N 200007 #define INF 0x3f3f3f3f #define LL long long LL a[N], b[N], f[N]; int main() { int T; scanf("%d", &T); b[0] = 0; while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) { scanf("%lld", &b[i]); b[i] += b[i - 1];} memset(f, -1, sizeof(f)); f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = i; j > 0; j--) { if (f[j - 1] == -1LL) continue; if (f[j - 1] + a[i] <= b[i]) { if (f[j] == -1) f[j] = f[j - 1] + a[i]; else f[j] = min(f[j], f[j - 1] + a[i]); } } } int ans = 0; for (int i = 1; i <= n; i++) if (f[i] != -1) ans = i; printf("%d\n", ans); } return 0; }