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 MAXN 20
long long n,m;
long long a[MAXN],b[MAXN];
long long preostalo[1<<MAXN];
long long pokriveno[1<<MAXN];
int main()
{
cin>>n>>m;
for (long long i=1;i<=n;i++) cin>>a[i];
for (long long i=1;i<=m;i++) cin>>b[i];
for (long long i=1;i<(1<<MAXN);i++) preostalo[i]=pokriveno[i]=-1;
preostalo[0]=pokriveno[0]=0;
for (long long suma=0;suma<(1<<m);suma++)
{
for (long long poslednji=0;poslednji<m;poslednji++)
{
if ((suma&(1<<poslednji))==0) continue;
long long prethodni=suma&((1<<poslednji)-1);
if (pokriveno[prethodni]==-1) continue;
long long noviostatak=preostalo[prethodni]+b[poslednji];
long long plata=a[pokriveno[prethodni]+1];
if (noviostatak<plata)
{
pokriveno[suma]=pokriveno[prethodni];
preostalo[suma]=noviostatak;
}
else if (noviostatak==plata)
{
pokriveno[suma]=pokriveno[prethodni]+1;
preostalo[suma]=0;
}
}
if (pokriveno[suma]==n) {cout<<"YES"<<endl;return 0;}
}
cout<<"NO"<<endl;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... |