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 <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define exit exit(false)
//#define here() cerr << "herewego\n";
#define show(x) cerr << #x << ": " << x << '\n';
#define int long long
//#define double long double
#define all(a) a.begin(), a.end()
#define whole(a, p, q) a+p, a+p+q
#define ioio() ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int sz = 50;
int a[sz], b[sz], n, m;
bool w[sz];
map <int, int> mp;
bool solve (int pos) {
if (pos == n + 1) {
return 1;
}
if (a[pos] == 0) {
return solve(pos + 1);
}
for (int i = 1; i <= m; i++) {
if (b[i] <= a[pos] && mp[b[i]]) {
a[pos] -= b[i];
mp[b[i]]--;
if (solve(pos)) {
return 1;
}
a[pos] += b[i];
mp[b[i]]++;
}
}
return 0;
}
signed main () { ioio();
// freopen("bank.in", "r", stdin);
// freopen("bank.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
mp[b[i]]++;
}
if (n == 1) {
int x = a[1];
for (int ma = 1; ma <= (1 << m); ma++) {
int sm = 0;
for (int i = 0; i < m; i++) {
if ((1 << i) & ma) {
sm += b[i+1];
}
}
if (sm == x) {
cout << "YES";
exit;
}
}
cout << "NO";
exit;
}
if (solve(1)) {
cout << "YES";
} else {
cout << "NO";
}
}
# | 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... |