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>
#define f first
#define s second
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0;i < n;i++)
cin >> a[i];
for(int i = 0;i < m;i++)
cin >> b[i];
bool ok = false;
vector<int> dp(1 << m, -1), o(1 << m);
dp[0] = 0;
for(int mask = 1;mask < (1 << m);mask++) {
for(int i = 0;(1 << i) <= mask;i++) {
if(!(mask & (1 << i)))
continue;
int s = mask ^ (1 << i);
if(dp[s] == -1)
continue;
int sm = o[s] + b[i];
int sl = a[dp[s]];
if(sm < sl) {
dp[mask] = dp[s];
o[mask] = sm;
}
else if(o[s] + b[i] == sl) {
dp[mask] = max(dp[mask], dp[s] + 1);
o[mask] = 0;
}
}
ok |= (dp[mask] == n);
}
cout << (ok ? "YES" : "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... |