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("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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |