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;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin>>n>>m;
vector<int> a(n), b(m);
int sa=0, sb=0;
for(int i=0;i<n;i++)cin>>a[i], sa+=a[i];
for(int i=0;i<m;i++)cin>>b[i], sb+=b[i];
if(sa>sb)return cout<<"NO\n", 0;
else if(sa<sb){
n++;
a.push_back(sb-sa);
}
vector<int> pref(n+1, 0);
for(int i=0;i<n;i++)pref[i+1]=pref[i]+a[i];
int dp[1<<m]={0};
for(int i=1;i<(1<<m);i++){
int sum=0;
for(int j=0;j<m;j++)if(i&(1<<j))sum+=b[j];
for(int j=0;j<m;j++){
if(i&(1<<j)){
int p=dp[i^(1<<j)];
int s=pref[p];
if(sum-s==a[p])dp[i]=max(dp[i], p+1);
else dp[i]=max(dp[i], p);
}
}
}
if(dp[(1<<m)-1]==n)cout<<"YES\n";
else cout<<"NO\n";
return 0;
}
# | 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... |