#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e6 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
ll res = 1;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
ll inv(ll x){
return bp(x, mod - 2);
}
int a[N], b[N], n, m, dp[N], r[N];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
for(int mask = 0; mask < (1 << m); mask++){
dp[mask] = -1;
}
dp[0] = 0;
for(int mask = 0; mask < (1 << m); mask++){
for(int dig = 0; dig < m; dig++){
if((mask & (1 << dig)) > 0){
int nw = mask ^ (1 << dig);
if(dp[nw] == -1) continue;
int mx = dp[nw], rem = r[nw];
if(rem + b[dig] == a[mx]){
mx++;
rem = 0;
} else rem += b[dig];
if(mx >= dp[mask]){
dp[mask] = mx;
r[mask] = rem;
}
}
}
if(dp[mask] == n){
cout << "YES";
return 0;
}
}
cout << "NO";
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... |