/* -*- coding: utf-8 -*- * * 393.cc: No.393 2本の竹 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_M = 60; /* typedef */ /* global variables */ int as[MAX_M], dp[2][MAX_N + 1]; /* subroutines */ /* main */ int main() { int tn; cin >> tn; while (tn--) { int n0, n1, m; cin >> n0 >> n1 >> m; for (int i = 0; i < m; i++) cin >> as[i]; sort(as, as + m); memset(dp, -1, sizeof(dp)); dp[0][0] = 0; int cur = 0, nxt = 1, asum = 0; for (int i = 0; i < m; i++) { bool cont = false; memset(dp[nxt], -1, sizeof(dp[nxt])); for (int j = 0; j <= n0; j++) if (dp[cur][j] >= 0) { int d = dp[cur][j] + 1; int j0 = j + as[i]; if (j0 <= n0 && dp[nxt][j0] < d) dp[nxt][j0] = d, cont = true; int j1 = asum - j + as[i]; if (j1 <= n1 && dp[nxt][j] < d) dp[nxt][j] = d, cont = true; } if (! cont) break; asum += as[i]; cur ^= 1, nxt ^= 1; } int maxdp = 0; for (int i = 0; i <= n0; i++) if (maxdp < dp[cur][i]) maxdp = dp[cur][i]; printf("%d\n", maxdp); } return 0; }