This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef pair<double, double> dodo;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
int N, M;
int A[20], B[20];
unordered_map<int, int> table;
unordered_map<int, int> tblbits;
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
sort(A, A+N);// reverse(A, A+N);
for (int i = 0; i < M; i++) cin >> B[i];
sort(B, B+M);// reverse(B, B+M);
int mlim = 1<<M;
int used = 0;
for (int i = 0; i < N; i++) {
bool flag = false;
int best = mlim-1;
int bestbits = 20;
for (int m = mlim-1; m > 0; m--) {
if (m & used) continue;
if (!table[m]) {
int sum = 0, bits = 0;
for (int k = 0; k < M; k++) if (m & (1<<k)) sum += B[k], bits += 1;
table[m] = sum;
tblbits[m] = bits;
}
if (table[m] == A[i]) {
flag = true;
if (tblbits[m] < bestbits) {
bestbits = tblbits[m];
best = m;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
used |= best;
}
cout << "YES" << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |