#include <bits/stdc++.h>
using namespace std;
#define chinatsu ios_base::sync_with_stdio(false);
#define kano cin.tie(nullptr); cout.tie(nullptr)
#define int long long
#define double long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7;
const int INF = 1e18;
vector<vector<int>> dp(1048576, vector <int> (21,INF));
void solve() {
int n, m;
cin >> n >> m;
int a[n + 2], b[m + 2];
int s = 0;
for (int i = 0; i < n; i ++) cin >> a[i];
for (int i = 0; i < m; i ++) cin >> b[i];
dp[0][0] = a[0];
int ans = 0, sum = 0;
for (int i = 0; i < (1<< m); i ++) {
sum = 0;
for (int j = 0; j < m; j++) {
int r = i& (1<< j);
if (r ) {
s = i ^ (1<< j);
for ( r =0; r < n; r ++) {
if( dp[s][r] - b[j] >= 0 && dp[s][r] != INF) {
dp[i][r] = dp[s][r] - b[j];
if ( dp[s][r] - b[j] == 0 ) {
if ( r + 1 < n) dp[i][r + 1] =a[r + 1];
else ans = 1;
}
}
}
}
}
}
if (ans) cout << "YES" << endl;
else cout << "NO" << endl;
}
signed main(){
chinatsu kano;
int t = 1;
//cin >> t;
while(t--){
solve();
}
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... |