#include using namespace std; template istream& operator>>(istream& is, pair& a){ return is >> a.first >> a.second; } template ostream& operator<<(ostream& os, pair& a){ return os << a.first << " "< istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; } template ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; } #define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++) #define ALL(v) (v).begin(), (v).end() #define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());} const int INF = 1 << 30; int main(){ int N, M; vector< int > A, B; cin >> N; A.resize(N); cin >> A; cin >> M; B.resize(M); cin >> B; vector< int > Cost(1 << N, 0); for(int i = 0; i < 1 << N; i++){ for(int k = 0; k < N; k++){ if((i >> k) & 1){ Cost[i] += A[k]; } } } vector< int > dp(1 << N, INF); dp[0]= 0; for(int i = 0; i < M; i++){ for(int k = (1 << N) - 1; k >= 0; k--){ // 買ってあるやつが1 if(dp[k] == INF) continue; for(int l = (1 << N) - 1; l >= 0; l--){ //買うやつが1 if(k & l || Cost[l] > B[i]) continue; dp[k | l] = min( dp[k | l], dp[k] + 1); } } } if(dp[(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; }