This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
int n, m;
cin >> n >> m;
int a[n], b[m];
for(int i = 0; i < n; i++)cin >> a[i];
int sum = 0;
for(int j = 0; j < m; j++){
cin >> b[j];
sum += b[j];
}
if(n == 1){
for(int mask = 0; mask < (1 << m); mask++){
int num = a[0];
for(int i = 0; i < m; i++){
if((1 << i) & mask){
num -= b[i];
}
}
if(num == 0){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
} else{
vector<int> index;
for(int i = 0; i < m; i++){
index.pb(i);
}
bool ok = false;
do{
int j = 0;
for(int i = 0; i < n; i++){
if(j == m)break;
int num = a[i];
while(j < m and b[index[j]] <= num){
num -= b[index[j]];
j++;
}
if(num != 0)break;
if(num == 0 and i == n - 1)ok = true;
}
if(ok)break;
}while(next_permutation(all(index)));
if(ok)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... |