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>
using namespace std;
#define _us using
#define _tp template
#define _tn typename
#define _ot cout <<
#define _er cerr <<
#define _in cin >>
#define _p << ' ' <<
#define _nl '\n'
#define _el << _nl
#define _rg(i, s, e) for (auto i = s; i < e; ++i)
#define _up(i, e) _rg(i, 0, e)
#define _ce constexpr
#define _cs const
#define _st static
#define _il inline
_us ll = long long;
_tp<_tn _t> _us vec = vector<_t>;
_tp<_tn _t> _us dbl = pair<_t, _t>;
_us sz = size_t;
_us u32 = uint32_t;
#define _mp make_pair
#define _f first
#define _s second
int n, m;
int a[20], b[20];
pair<int, u32> r[20];
u32 S = 0u;
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
_in n >> m;
_up(i, n) _in a[i];
_up(i, m) _in b[i];
sort(a, a+n);
sort(b, b+m);
//_up(i,n) _er a[i] << ' '; _er _nl;
//_up(i,m) _er b[i] << ' '; _er _nl;
_up(i, m) r[i] = _mp(0, 0u);
_up(k, n) {
auto ak = a[k];
// _er "=>" _p ak _el;
_up(i, m) r[i]._f = ak;
//_up(i,m) _er r[i]._f << ' '; _er _nl;
for (auto i = m-1; i >=0; --i) {
// _er "::" _p b[i] _el;
if (!(S&(1<<i))) {
// _er " ";
_rg(j, i, m) {
// _er "" _p b[j];
if (r[j]._f - b[i] >= 0) {
r[j]._f -= b[i];
r[j]._s |= 1<<i;
}
if (r[j]._f == 0) {
S = r[j]._s;
goto next;
}
} //_er _nl;
}
//_up(i,m) _er r[i]._f << ' '; _er _nl;
}
_ot "NO" _el;
return 0;
next:;
}
_ot "YES" _el;
}
# | 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... |