Submission #1101445

#TimeUsernameProblemLanguageResultExecution timeMemory
1101445dead0neBank (IZhO14_bank)C++17
100 / 100
136 ms8696 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<long long,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 1000000007
#define MX 1505
using namespace std;


void solve(){
    int n,m; cin >> n >> m;
    int pref[n], moni[m];
    for(int i=0; i<n; i++) cin >> pref[i];
    for(int i=1; i<n; i++) pref[i]+=pref[i-1];
    for(int i=0; i<m; i++) cin >> moni[i];
    int dp[1<<m];
    dp[0]=-1;
    for(int i=1; i<1<<m; i++){
        dp[i]=-1;
        int sum=0;
        for(int j=0; j<m; j++) if(i&1<<j) sum+=moni[j];
        for(int j=0; j<m; j++){
            if(!(i&1<<j)) continue;
            dp[i]=max(dp[i], dp[i^1<<j]);
            if(sum==pref[dp[i^1<<j]+1]) dp[i]=max(dp[i], dp[i^1<<j]+1);
            if(dp[i]==n-1){
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

 
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif
 
    /*freopen(".in","r",stdin);
    freopen(".out","w",stdout);*/

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