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>
typedef long long ll;
#define FOR(i,x,y) for (ll i = (x); i < (y); i++)
using namespace std;
set<ll> dp[21];
map<ll, vector<ll>> idk;
//cd "/home/s/saco06/Desktop/" && g++ bank.cpp -o bank && "/home/s/saco06/Desktop/"bank
int main(){
ll n,m;
cin >> n >> m;
ll sum1=0, sum2=0;
vector<ll> lis1(n);
vector<ll> lis2(m);
FOR(i,0,n){
cin >> lis1[i];
sum1 += lis1[i];
}
FOR(i,0,m){
cin >> lis2[i];
sum2 += lis2[i];
}
if (sum1 > sum2){
cout << "NO";
return 0;
}
for (auto&i : lis1){
idk[i] = {};
}
FOR(i, 0, (1<<m)){
ll sum = 0;
FOR(j,0,m){
if (i & (1<<j)){
sum += lis2[j];
}
}
if (idk.count(sum)){
idk[sum].push_back(i);
}
}
sort(lis1.begin(), lis1.end());
for (auto&i : idk[lis1[0]]){
dp[0].insert(i);
}
FOR(i, 0, n-1){
for (auto&j : dp[i]){
for (auto&k : idk[lis1[i+1]]){
if (j&k) continue;
dp[i+1].insert(j|k);
}
}
}
if (dp[n-1].size()){
cout << "YES";
}else{
cout << "NO";
}
}
# | 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... |