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>
#define ll long long
#define fi first
#define se second
#define ve vector
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
using namespace std;
mt19937 rnd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
void solve(){
int n, m;
cin >> n >> m;
ve<int> a(n);
ve<int> b(m);
for(auto& i : a)
cin >> i;
for(auto& j : b)
cin >> j;
ve<int> cur(1 << m, -1);
ve<int> lefts(1 << m, -1);
cur[0] = lefts[0] = 0;
for(int i = 1; i < (1 << m); i++){
for(int j = 0; j < m; j++){
if(!((i >> j) & 1))
continue;
int prev = i ^ (1 << j);
if(cur[prev] == -1)
continue;
int li = lefts[prev] + b[j];
if(li > a[cur[prev]])
continue;
if(li == a[cur[prev]]){
cur[i] = cur[prev] + 1;
lefts[i] = 0;
}
else{
cur[i] = cur[prev];
lefts[i] = li;
}
if(cur[i] == n){
cout << "YES";
return;
}
}
}
cout << "NO";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while(T--){
solve();
}
}
# | 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... |