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 pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int N = 1e6+4, mod = 1e9+7;
int n, m, ans = 0;
int a[21];
map<multiset<int>, bool>mp;
multiset<int> b;
bool ok = 1;
int cn = 0;
void ch(){
if(mp[b] || !ok)return;
mp[b]=true;
if(cn == n){cout << "YES\n";ok = 0;return;}
multiset<int> st = b;
for(int ms = 1; ms < (int)(1<<b.size()); ms++){
vi res;
int cnt = 0, sum = 0;
for(int i:b){
if((ms>>cnt) & 1){
sum+=i;
res.pb(i);
}
cnt++;
//~ cout << ((ms >> cnt)&1);
if(sum > a[cn])break;
}
//~ cout << endl;
if(sum == a[cn]){
for(int i:res)b.erase(b.find(i));
cn++;
ch();
cn--;
b = st;
}
}
}
void solve(){
cin >> n >> m;
for(int i = 0; i < n; i++)cin >> a[i];
for(int i = 0; i < m; i++){int x;cin >> x;b.insert(x);}
ch();
if(ok)cout << "NO\n";
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//~ cin >> test;
while(test--){
solve();
}
}
Compilation message (stderr)
bank.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
59 | main(){
| ^~~~
# | 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... |