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;
bool dp[(1 << 20)+1][21];
long long res[(1 << 21)];
bool ok = false;
long dept[50], money[50], pre[50], n, m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
for(long i = 1; i <= n; i++){
cin >> dept[i];
pre[i] = pre[i-1] + dept[i];
}
for(long i = 0; i < m; i++) cin >> money[i];
for(long i = 0; i < (1 << m); i++){
dp[i][0] = true;
for(long p = 0; p < m; p++){
if(i & (1 << p)){
res[i] = res[i] + money[p];
}
}
}
for(long i = 1; i <= n; i++){
for(long j = 0; j < (1 << m); j++){
for(long p = 0; p < m; p++){
if(!(j & (1 << p))){
long u = j | (1 << p);
if(dp[j][i] == true){
dp[u][i] = true;
if(i == n) ok = true;
}
if(dp[j][i-1] == true){
if(res[u] - pre[i-1] == dept[i]){
dp[u][i] = true;
if(i == n) ok = true;
}
}
}
}
}
}
if(ok == true) cout << "YES";
else cout << "NO";
}
# | 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... |