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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
void solve() {
int n,m;
cin >> n >> m;
vi a(n+2),b(m+1);
F(i,n) cin >> a[i];
F(i,m) cin >> b[i];
a[n+1] = 2e18;
int lim = (1<<m);
vector<pii> dp(lim,{-1,2e18});
dp[0] = {0,0};
for (int mask=1;mask<lim;mask++) {
for (int bank = 0;bank < m; bank++) {
if (!(mask & (1<<bank))) continue;
int rem = mask^(1<<bank);
int need = a[dp[rem].first+1]-dp[rem].second;
if (b[bank+1] == need) dp[mask] = max(dp[mask],{dp[rem].first+1,0});
else dp[mask] = max(dp[mask],{dp[rem].first,dp[rem].second+b[bank+1]});
}
}
if (dp[lim-1].first == n) cout << "YES\n";
else cout << "NO\n";
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) 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... |