# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1086863 | lhlephuocdao | Bank (IZhO14_bank) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
const int MAX = 20;
int N, M;
int a[MAX + 10], b[MAX + 10], l[MASK(MAX) + 10], f[MASK(MAX) + 10];
void solve()
{
cin >> N >> M;
for(int i=0; i<N; i++){
cin >> a[i];
}
for(int i=0; i<M; i++){
cin >> b[i];
}
memset(f, -1, sizeof f);
f[0] = 0;
for(int mask=0; mask < (1<<M); mask++)
if(f[mask] != -1){
for(int i=0; i < M; i++)
if(!(mask & (1<<i))){
int x = b[i] + l[mask];
if(x < a[f[mask]]){
f[mask | (1<<i)] = f[mask];
l[mask | (1<<i)] = x;
}
else if(x == a[f[mask]]){
f[mask | (1<<i)] = f[mask] + 1;
l[mask | (1<<i)] = 0;
}
if(f[mask | (1<<i)] == N){
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}