이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
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... |