#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector < ll > vl;
typedef set < ll > setl;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define pll pair<ll, ll>
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll mod = 1e9 + 7;
const int MAX = 3e5 + 5;
const int imax = 2147483647;
ll n, m, k, q, l, r;
ll a[MAX], b[MAX];
void solve(){;
cin >> n >> m;
FORI(i, n)cin >> a[i];
FORI(i, m)cin >> b[i];
vl qalan(1 << m, -1), cvb(1 << m, -1);
qalan[0] = 0;
cvb[0] = 0;
for(ll mask = 0; mask < (1 << m); mask++){
for(ll i = 0; i < m; i++){
if(mask & (1 << i)){
ll sonuncu = mask ^ (1 << i);
if(cvb[sonuncu] == -1)continue;
ll olan = b[i] + qalan[sonuncu];
ll isci = a[cvb[sonuncu]];
if(olan == isci){
cvb[mask] = cvb[sonuncu] + 1;
qalan[mask] = 0;
}
else if(olan < isci) {
cvb[mask] = cvb[sonuncu];
qalan[mask] = olan;
}
if(cvb[mask] == n){
cout << "YES";
return;
}
}
}
}
cout << "NO";
}
signed main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
sync;
ll t = 1;
// sieve(1e5);
// cin >> t;
FOR(i, t){
// cout << "Case #" << i << ": ";
solve();
}
}
# | 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... |