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 ff first
#define ss second
#define ll int
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
ll n,m,a[21],b[21],res,kt[10010],w=0;
void dao(ll i)
{
for (ll j=1;j<=n;j++)
if (a[j]>=b[i])
{
a[j]-=b[i];
if (a[j]==0) res--;
w++;
if (w==10000000) {cout<<"NO";exit(0);}
if (m-i>=res)
{
if (i==m)
{if (res==0){cout<<"YES";exit(0);}}
else dao(i+1);
}
if (a[j]==0) res++;
a[j]+=b[i];
}
}
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for (ll i=1;i<=n;i++)
cin>>a[i],kt[a[i]]++;
for (ll i=1;i<=m;i++)
{
cin>>b[i];
if (kt[b[i]]>0) kt[b[i]]--,i--,m--;
}
vector<ll> c;
for (ll i=1;i<=n;i++)
{
if (kt[a[i]]>0) c.push_back(a[i]);
kt[a[i]]--;
}
n=0;
for (ll j:c)
a[++n]=j;
n++;
a[n]=100010;
res=n-1;
dao(1);
cout<<"NO";
}
# | 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... |