// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <ctime>
#include <cassert>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <bitset>
#include <array>
using ll = long long;
#define debug(x) cout << #x << " = " << x << '\n'
#define separator "===============================================\n"
#define all(a) a.begin(), a.end()
#define SZ(a) (int)(a).size()
using namespace std;
const int mxn = 1e5 + 3;
const ll mod = 1e9 + 7;
const int inf32 = 2e9;
const ll inf64 = 3e18;
void solve(){
int n, m;
cin >> n >> m;
vector<int> a(n), b(m), pref;
for (int i = 0; i < n; ++i){
cin >> a[i];
if (pref.empty()) pref.push_back(a[i]);
else pref.push_back(pref.back() + a[i]);
}
for (int j = 0; j < m; ++j)
cin >> b[j];
vector<int> dp(1 << m);
for (int mask = 0; mask < (1 << m); ++mask){
int s = 0;
for (int i = 0; i < m; ++i) if (mask >> i & 1){
s += b[i];
dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
}
if (s == pref[dp[mask]]) ++dp[mask];
}
if (dp[(1 << m) - 1] == n) cout << "YES\n";
else cout << "NO\n";
}
int main(){
auto start = chrono::steady_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while(t--) solve();
chrono::duration<double> elapsed {chrono::steady_clock::now() - start};
cerr << "\n>> Runtime: " << elapsed.count() << "s\n";
}
# | 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... |