#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } int M; cin >> M; vector B(M); for (int i = 0; i < M; ++i) { cin >> B[i]; } sort(B.begin(), B.end()); reverse(B.begin(), B.end()); int ans = INT_MAX; do { int cur = 0; int remain = B[0]; bool ok = true; for (int i = 0; i < N; ++i) { while (remain < A[i] && cur < M) { ++cur; remain = B[cur]; } if (cur >= M) { ok = false; break; } remain -= A[i]; } if (ok) { ans = min(ans, cur + 1); } } while (next_permutation(A.begin(), A.end())); if (ans == INT_MAX) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }