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 int long long
#define vtr vector
#define vi vtr<int>
#define ii pair<int, int>
#define fi first
#define se second
#define len(s) (int)s.size()
#define fd(v, s, e) for (int v = s; v < e; ++v)
#define bk(v, s, e) for (int v = s-1; v >= e; --v)
#define farr(i, arr) for (auto i: arr)
#define all(arr) arr.begin(), arr.end()
using namespace std;
void presolve()
{
}
int n, m;
vi a, b;
bool ck = false;
void btr(int ind, int cur_i, int mask, int sum)
{
if (ind == n)
{
ck = true;
return;
}
if (sum == a[ind])
{
btr(ind+1, 0, mask, 0);
return;
}
fd (i, cur_i, m) if (!(mask & (1 << i)))
{
if (sum + b[i] > a[ind]) break;
btr(ind, i+1, mask + (1 << i), sum + b[i]);
if (ck) return;
}
}
void solve()
{
cin >> n >> m;
a.resize(n);
int mx = 0;
farr (&i, a) cin >> i, mx = max(mx, i);
fd (_, 0, m)
{
int x;
cin >> x;
if (x > mx) continue;
b.emplace_back(x);
}
m = b.size();
sort(all(b));
btr(0, 0, 0, 0);
cout << (ck? "YES" : "NO");
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
{ 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... |