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 in freopen ("bank.in", "r", stdin);
#define out freopen("bank.out", "w", stdout);
#define ll long long int
const int val = (2e5) + 5;
const int inf = (1e9) + 7;
double eps = 0.000000001;
using namespace std;
int n, m, a[25], b[25];
void rec(int id, int s, int mask){
if(id == n){
cout << "YES" << endl;
exit(0);
}
if(mask == (1<<m)-1 && id < n){
cout << "NO" << endl;
exit(0);
}
for(int i=0; i<m; ++i){
if((mask & (1 << i)) == 0){
if(s + b[i] < a[id]){
rec(id, s+b[i], mask | (1 << i));
}
else if(s + b[i] == a[id]){
rec(id+1, 0, mask | (1 << i));
}
}
}
}
int solve(){
cin >> n >> m;
for(int i=0; i<n; ++i){
cin >> a[i];
}
for(int i=0; i<m; ++i){
cin >> b[i];
}
rec(0, 0, 0);
cout << "NO" << endl;
}
int main(){
//in out
ios_base::sync_with_stdio(0);
solve();
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int solve()':
bank.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | 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... |