# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119726 | tsengang | Race (IOI11_race) | C++14 | 0 ms | 0 KiB |
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>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define pb push_back
#define ertunt return
#define vodka void
using namespace std;
ll n,m;
ll a[21];
ll b[21];
bool yes;
bool vis[21];
vodka dfs(ll x){
if(x > n-1){
yes = true;
ertunt;
}
for(ll i = 0; i < m; i++){
if(vis[i] == false){
if(b[i] <= a[x]){
a[x]-=b[i];
vis[i] = true;
if(a[x] == 0)dfs(x+1);
else dfs(x);
vis[i] = false;
a[x]+=b[i];
}
}
}
}
int main(){
cin >> n >> m;
if(n == 1){
ll a;
cin >> a;
ll b[m+1];
for(ll j = 1; j <= m; j++)cin >> b[j];
for(ll i = 1; i <= (1<<m); i++){
ll res = 0;
for(ll j = 0; j < m; j++){
if(i&(1<<j)){
res+=b[j];
}
}
if(res == a){
cout << "YES";
ertunt 0;
}
}
cout << "NO";
ertunt 0;
}
for(ll i = 0; i < n; i++) cin >> a[i];
for(ll i = 0; i < m; i++) cin >> b[i];
sort(a,a+n);
sort(b,b+m);
dfs(0);
if(yes)cout << "YES\n";
else cout << "NO";
}