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>
// #define int long long
using namespace std;
const int N = 2e5 + 11;
const int maxn = 1e6 + 11;
const int inf = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, m, a[N], b[N], ok = 0;
int ps[(1 << 20)];
void f(int pos, int mm){
if(pos == n + 1) ok = 1;
if(ok) {
return;
}
for(int mask = 0; mask < (1 << m); mask++){
int sum = ps[mask];
if(mask & mm) continue;
if(sum == a[pos]) f(pos + 1, (mask | mm));
if(ok){
return;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int x = 0;
int y = 0;
for(int i = 1; i <= n; i++) x += a[i];
for(int i = 1; i <= m; i++) if(b[i] <= a[n]) y += b[i];
if(y < x){
cout << "NO\n";
return 0;
}
for(int mask = 0; mask < (1 << m); mask++){
int sum = 0;
for(int i = 0; i < m; i++){
if(mask >> i & 1) sum += b[i];
}
ps[mask] = sum;
}
f(0, 0);
cout << (ok? "YES":"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... |