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;
typedef long long ll;
typedef long double ld;
pair <int, int> dp[2000005];
int a[25];
int b[25];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int j=0; j<m; j++){
cin >> b[j];
}
for(int mask=0; mask<(1<<m); mask++){
if(dp[mask].first == 0 && dp[mask].second == 0 && mask > 0) continue;
for(int i=0; i<m; i++){
if((1<<i)&mask) continue;
int k = a[dp[mask].first+1] - dp[mask].second;
if(k < b[i]) continue;
else if(k == b[i]) dp[mask|(1<<i)] = {dp[mask].first+1, 0};
else dp[mask|(1<<i)] = {dp[mask].first, dp[mask].second+b[i]};
}
}
for(int i=0; i<(1<<m); i++){
if(dp[i].first == n){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
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... |