#include #include #include #include #include #include using namespace std; #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).begin(), (x).end(), greater() ) #define CLEAR(d) memset((d), 0, (sizeof((d)))) int main() { int n, m, ans = 0, g = 0; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> m; vector b(m); for (int i = 0; i < m; i++) { cin >> b[i]; } RSORT(a); RSORT(b); int t[10]; CLEAR(t); for (ans = 0; ans < m; ans++) { int sum = b[ans]; for (int i = 0; i < n; i++) { if (t[i] == 0 && sum >= a[i]) { sum -= a[i]; t[i] = 1; } } int flag = 0; for (int i = 0; i < n; i++) { if (t[i] == 0) { flag = 1; break; } } if (flag == 0) { g = 1; break; } } if (g == 0) ans = -2; printf("%d\n", ans+1); return 0; }