Submission #955127

#TimeUsernameProblemLanguageResultExecution timeMemory
955127andrewpBank (IZhO14_bank)C++14
100 / 100
107 ms16984 KiB
//Dedicated to my love, ivaziva
#define here cerr<<"---------------------------------\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
#define ll long long
#define ld long double
#define llinf 100000000000000000LL
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define sz(s) (ll)(s.size())
#define ios ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
#define mod 1000000007
using namespace std;
/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
ll add(ll x,ll y){
    if(x+y>=mod) return x+y-mod;
    return x+y;
}
ll sub(ll x,ll y){
    if(x-y<0) return x-y+mod;
    return x-y;
}
ll mul(ll x,ll y){
    ll res=(x*y)%mod;
    if(res<0) res+=mod;
    return res;
}
ll pw(ll x,ll y){
	ll ret=1,bs=x;
	for(;y;y>>=1){
		if(y&1) ret=mul(ret,bs);
		bs=mul(bs,bs);
	}
	return ret%mod;
}*/
#define maxn 20
ll n,m;
ll a[maxn];
ll b[maxn];
void tc(){
    cin >> n >> m;
    for(ll i = 0;i<n;i++) cin >> a[i];
    for(ll i = 0;i<m;i++) cin >> b[i];
    bool ans = 0;
    vector<ll> dp(1<<m,-1),os(1<<maxn,0);
    dp[0] = 0;
    for(ll msk = 1;msk<(1<<m);msk++){
        for(ll i = 0;i<m;i++){
            if(!(msk&(1<<i))) continue;
            ll sub = msk^(1<<i);
            if(dp[sub]==-1) continue;
            ll im = os[sub]+b[i];
            ll tr = a[dp[sub]];
            if(im<tr){
                dp[msk] = dp[sub];
                os[msk] = im;
            }else if(im==tr){
                dp[msk] = max(dp[msk],dp[sub]+1);
                os[msk] = 0;
            }
        }
        ans|=(dp[msk]==n);
    }
    cout<<(ans?"YES":"NO")<<endl;
}
int main(){
	ios
    //freopen("guard.in","r",stdin);
    //freopen("guard.out","w",stdout);
    int t; t = 1;
//    cin >> t;
    while(t--){
        tc();
    }
	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...