#include #include #define INF (2 << 28) using namespace std; int n, m; int a[11], b[11], dp[1<<10][1<<10]; int rec(int toy, int used){ //cout << toy << " " << used << endl; if(toy == 0) return __builtin_popcount(used); if(dp[toy][used]) return dp[toy][used]; int ret = INF; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(a[i] <= b[j] && toy >> i & 1){ b[j] -= a[i]; ret = min(ret, rec(~(1 << i) & toy, used | (1 << j))); b[j] += a[i]; } } } return dp[toy][used] = ret; } int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; cin >> m; for(int i = 0; i < m; i++) cin >> b[i]; int d = rec((1<