This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Freedom will be ours
#include<bits/stdc++.h>
#define ones(x) __builtin_popcount(x)
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 21, M = 21;
int dp[1 << M], rem[1 << M], mark[1 << M], y;
int high(int x){
for(int i = 20; i >= 0; i--)
if(x & (1 << i))
return i;
return 0;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int& i : a) cin >> i;
for(int& i : b) cin >> i;
mark[0] = 1;
for(int mask = 0; mask < (1 << m); mask++){
for(int i = 0; i < m; i++){
if(mark[mask ^ (1 << i)] and (mask & (1 << i))){
int last = dp[mask ^ (1 << i)];
int curr = rem[mask ^ (1 << i)] + b[i];
if(curr > a[last]) continue;
dp[mask] = last + (curr == a[last] ? 1 : 0);
rem[mask] = (curr == a[last] ? 0 : curr);
mark[mask] = 1;
}
}
if(dp[mask] == n) y = 1;
}
cout << (y ? "YES" : "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... |