제출 #362736

#제출 시각아이디문제언어결과실행 시간메모리
362736sumit_kk10은행 (IZhO14_bank)C++14
19 / 100
138 ms30316 KiB
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 2;
vector<int> pos[N];
int n, m, a[N], b[N];
bool vis[N];

void gen(int i, long long sum, vector<int>& cur){
    if(i == m){
        long long power = 0;
        for(auto k : cur)
            power = (power | k);
        pos[sum].push_back(power);
        return;
    }
    vector<int> cur1 = cur;
    gen(i + 1, sum, cur1);
    cur1.push_back(i);
    gen(i + 1, sum + b[i], cur1);
}

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];
    vector<int> ok;
    gen(0, 0, ok);
    for(int i = 0; i < n; ++i){
        long long sum = a[i];
        bool yes = 0;
        for(auto k : pos[sum]){
            bool no = true;
            for(int j = 0; j < m; ++j){
                if(k & (1LL << j)){
                    if(vis[j]){
                        no = 0;
                        break;
                    }
                }
            }
            if(no){
                yes = true;
                for(int j = 0; j < m; ++j)
                	if(k & (1LL << j))
                		vis[j] = true;
                break;
            }
        }
        if(!yes){
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}

int main() {
    fast;
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...