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
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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];
int aa = 1LL << m;
vector<int> dp(aa,0), resto(aa,0);
for(int i=1; i<aa; i++){
for(int j=0; j<m; j++){
int bit = 1LL << j;
if((i&bit) == 0) continue;
if(dp[i-bit] == n) dp[i] = n;
else{
int aux = dp[i-bit], rest = resto[i-bit];
if(rest + b[j] == a[aux]){
aux++;
rest = 0;
}
else rest += b[j];
if(aux >= dp[i]){
dp[i] = aux;
resto[i] = max(rest, resto[i]);
}
}
}
}
if(dp[aa-1] == n) cout << "YES" << endl;
else cout << "NO" << endl;
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... |