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;
int main(){
//n people, m banknotes
int n, m;
cin >> n >> m;
int salary[n];
int banknote[m];
int store = 0;
for (int i = 0; i < n; i++){
cin >> salary[i];
salary[i] += store;
store = salary[i];
}
for (int i = 0; i < m; i++)
cin >> banknote[i];
int dp[1<<m];
int sum[1<<m];
memset(dp, 0, sizeof(dp));
memset(sum, 0, sizeof(sum));
for (int i = 0; i < (1<<m); i++){
if (dp[i] == n){
cout<<"YES"<<endl;
return 0;
}
for (int j = 0; j < m; j++){
if ((i&(1<<j)) != 0) continue;
sum[i^(1<<j)] = sum[i]+banknote[j];
if (salary[dp[i]] == sum[i]+banknote[j])
dp[i^(1<<j)] = max(dp[i^(1<<j)], dp[i]+1);
else
dp[i^(1<<j)] = max(dp[i^(1<<j)], dp[i]);
}
}
cout<<"NO"<<endl;
}
# | 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... |