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;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m;
cin >> n >> m;
vi a(n), b(m);
for(int &i : a)
cin >> i;
for(int &i : b)
cin >> i;
vi leftover(1 << m, -1), covered(1 << m, -1);
leftover[0] = covered[0] = 0;
for(int i = 0; i < (1 << m); i++){
for(int last = 0; last < m; last++){
int prev = i ^ (1 << last);
if(!(i & (1 << last)) || covered[prev] == -1) continue;
int new_amt = leftover[prev] + b[last], cur_target = a[covered[prev]];
if(new_amt < cur_target){
covered[i] = covered[prev];
leftover[i] = new_amt;
}
else if(new_amt == cur_target){
covered[i] = covered[prev] + 1;
leftover[i] = 0;
}
}
if(covered[i] == n){
cout << "YES"; return 0;
}
}
cout << "NO";
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... |