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 int long long
const int mod = 1e9 + 7, N = 2e5 + 5;
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int tt = 1; //cin >> tt;
while(tt--){
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
vector<int> ans((1 << m), -1), left((1 << m), -1);
ans[0] = left[0] = 0;
for(int i = 0; i < (1 << m); i++){
for(int j = 0; j < m; j++){
if(!(i & (1 << j))) continue;
int p = i & ~(1 << j);
if(ans[p] == -1) continue;
int sum = left[p] + b[j];
int need = a[ans[p]];
if(sum < need){
ans[i] = ans[p];
left[i] = sum;
}else if(sum == need){
ans[i] = ans[p] + 1;
left[i] = 0;
}
}
if(ans[i] == n){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
}
Compilation message (stderr)
bank.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | 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... |