#include #include #include using namespace std; int n1, n2; vector a; vector DP; int n0,n1sa,n2sa; bool solve(int sum,int first); int main() { int d,m; cin >> d; for (int i = 0; i < d; i++) { cin >> n1 >> n2; cin >> m; a.resize(m); for (int j = 0; j < m; j++) { cin >> a[j]; } sort(a.begin(), a.end()); n0 = n1 + n2; for (int j=0; j < a.size(); j++) { if (a[j] <= n0) { n0 -= a[j]; }else { a.erase(a.begin() + j); j--; } } if(n0>=n1){ cout<= n1sa&&tmp <= n1) || (tmp >= n2sa&&tmp <= n2)) { return true; } else if (tmp > n1) continue; if (DP[tmp] <= i) continue; else { DP[tmp] = i; if (solve(tmp,i+1)) return true; } } return false; }