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;
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;
for (int m = mlim-1; m > 0; m--) {
if (m & used) continue;
if (!table[m]) {
int sum = 0;
for (int k = 0; k < M; k++) if (m & (1<<k)) sum += B[k];
table[m] = sum;
//cerr << "m: " << m << " val: " << table[m] << endl;
}
if (table[m] == A[i]) {
used |= m;
flag = true;
break;
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
}
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... |