This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
// #pragma GCC target("avx,avx2,sse4")
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n,m;cin>>n>>m;
vector<int> a(n);
for (int &x:a)cin>>x;
vector<int> b(m);
for (int &y:b)cin>>y;
vector<int> covered(1<<m,0), leftover(1<<m, 0);
for (int s=1;s<(1<<m);s++) {
int cp=s;
int cnt=0;
while (cp) {
if ((cp&1)==1) {
int pv=s ^ (1<<cnt);
if (covered[pv] == n) {
covered[s]=n;
leftover[s]=0;
}
else {
int amount = leftover[pv] + b[cnt];
int fnd = a[covered[pv]];
if (amount == fnd && covered[pv] + 1 > covered[s]) {
covered[s] = covered[pv]+1;
leftover[s] = 0;
}
else if (amount < fnd && covered[pv] >= covered[s]) {
covered[s] = covered[pv];
leftover[s] = amount;
}
}
}
cp>>=1;
cnt++;
}
// cout<<covered[s]<<" "<<s<<"\n";
}
if (covered.back() == n) {
cout<<"YES\n";
}
else {
// cout<<covered.back()<<"\n";
cout<<"NO\n";
}
}
# | 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... |