This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
ll n, m, arr[25], brr[25];
vector<ll>ma;
map<ll, ll>val;
map<ll, vector<ll> >mask;
void fun(){
cin>>n>>m;
for(int i = 1; i <= n; i++)cin>>arr[i];
for(int i = 1; i <= m; i++)cin>>brr[i];
ma.push_back(0);
val[0] = 0;
mask[0].push_back(0);
for(int i = 1; i <= m; i++){
for(auto it : ma){
if((it & (1 << (i - 1))))
continue;
ll cur = it + (1 << (i - 1));
mask[val[it] + brr[i]].push_back(cur);
val[cur] = val[it] + brr[i];
ma.push_back(cur);
}
}
vector<ll>ms[25];
ms[0].push_back(0);
for(int i = 1; i <= n; i++){
for(auto it : mask[arr[i]]){
for(auto tt : ms[i - 1]){
if((it & tt) == 0)
ms[i].push_back(it | tt);
}
}
}
if(ms[n].size())
cout<<"YES\n";
else
cout<<"NO\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int ttt = 1;
//cin>>ttt;
while(ttt--)fun();
}
# | 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... |