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>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define tup tuple<int, int, int>
#define pii pair<int, int>
#define fi first
#define se second
#define pub push_back
#define pob pop_back
int n, m;
signed main() {
ioss;
cin >> n >> m;
vector<int> a(n+2), b(m+2);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
vector<int> num[20004];
for(int i = 0; i < (1 << m); i++) {
int cur = 0;
for(int j = 0; j < m; j++) {
if(i & (1 << j)) cur += b[j];
}
num[cur].pub(i);
}
bool vis[m+2] = {};
bool ok = 1;
for(int i = 0; i < n; i++) {
if(num[a[i]].size() == 0) {
ok = 0;
break;
}
for(auto idx : num[a[i]]) {
bool done = 1;
for(int j = 0; j < m; j++) {
if(idx & (1 << j)) {
if(vis[j]) {
done = 0;
break;
}
vis[j] = 1;
}
}
if(done) break;
}
}
cout << (ok ? "YES" : "NO") << endl;
}
# | 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... |