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("Ofast,no-stack-protector,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
vector<int>a(N),b(N);
int n,m,ind[1<<20],dp[1<<20];
int32_t main()
{
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
for(int mask = 0;mask < n;mask++){
for(int i=0;i<m;i++){
if(mask&(1<<i)){
if(dp[mask ^ (1 << i)] == -1){
continue;
}
int cur = a[dp[mask ^ (1<<i)]] , r = ind[mask ^ (1<<i)];
if(r + b[i] < cur) {
dp[mask] = dp[mask ^ (1<<i)];
ind[mask] = r + b[i];
}
else if(r + b[i] == cur) {
dp[mask] = dp[mask ^ (1<<n)] + 1;
ind[mask] = 0;
}
if(dp[mask] == N){
cout << "YES";
return 0;
}
}
}
}
cout<<"NO\n";
return 0;
}
/*
1 1 2 2 3 3 4 4
1
*/
# | 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... |