Submission #856612

#TimeUsernameProblemLanguageResultExecution timeMemory
856612yash_9a3bBank (IZhO14_bank)C++17
44 / 100
80 ms460 KiB
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define endl '\n'
#define int long long
#define f first
#define mp make_pair
#define s second
using namespace std;

int n, m;
int p[20], b[20];

signed main()
{
    fast;
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    if(m <= 10){
        sort(b, b + m);
        do{
            int add = 0, tot = 0;
            for(int i = 0; i < m; i++){
                tot += b[i];
                if(add == n) break;
                if(tot > p[add]) break;
                if(tot == p[add]) add++, tot = 0;
            }
            if(add == n){
                cout << "YES" << endl; return 0;
            }
        }while(next_permutation(b, b+m)); 
        cout << "NO" << endl;
    }
    else{
        bool ans = false;
        for(int msk = 0; msk < (1 << m); msk++){
            int add = 0;
            for(int i = 0; i < m; i++) if(msk & (1 << i)) add += b[i];
            if(add == p[0]) ans = true;
        }
        cout << (ans ? "YES" : "NO") << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...