/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: %%%%%%%%%%% %%%% %%%% %% %%━━■%% %% %% %% %%% %% % %% %% % %%%%■% %% %%% %% %%% %%%%%%%%%%%%%%■%% %%%%%% */ #include #include #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } template inline void operator () (T &x) { x = *this; } template inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 2020; ll a[maxn], b[maxn]; ll f[maxn][maxn]; int main () { int T = read; while (T --) { int n = read; for (int i = 1; i <= n; i ++) read(a[i]); for (int i = 1; i <= n; i ++) b[i] = b[i - 1] + read; for (int i = 1; i <= n; i ++) for (int j = 1; j <= i; j ++) { f[i][j] = j == i ? 1000000000000000000 : f[i - 1][j]; if (f[i - 1][j - 1] + a[i] <= b[i]) f[i][j] = std::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] < 1000000000000000000) ans = i; printf("%d\n", ans); } }