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 ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 20+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int a[N] , b[N];
int n , m;
pair<int,int> dp[(1 << 21)];
void solve(int tc) {
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
for(int i = 1; i <= m; i ++) {
cin >> b[i];
}
sort(b+1, b+m+1);
for(int mask = 1; mask < (1 << m); mask ++) {
for(int i = 1; i <= m; i ++) {
if(mask & (1 << i-1)) {
int p = mask - (1 << i-1);
if(dp[p].S + b[i] == a[dp[p].F+1]) {
dp[mask] = max(dp[mask] , {dp[p].F+1 , 0});
}
else {
dp[mask] = max(dp[mask] , {dp[p].F , dp[p].S+b[i]});
}
}
}
}
if(dp[(1 << m) - 1].F == n) {
cout << "YES";
}
else
cout << "NO";
}
/*
*/
main() {
ios;
int tt = 1 , tc = 0;
// cin >> tt;
while(tt --) {
solve(++tc);
}
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void solve(int)':
bank.cpp:30:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
30 | if(mask & (1 << i-1)) {
| ~^~
bank.cpp:31:27: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
31 | int p = mask - (1 << i-1);
| ~^~
bank.cpp: At global scope:
bank.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | 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... |