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;
#ifdef LOCAL
#define debug(x) cout << (#x) << " is " << (x) << '\n'
#else
#define debug(x) 42
#endif
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int>a(n), b(m);
for (int i = 0; i < n; i++)cin >> a[i];
for (int j = 0; j < m; j++)cin >> b[j];
int f[(1 << m)], p[(1 << m)];
memset(f, -1, sizeof(f));
memset(p, -1, sizeof(p));
bool ok = 0;
f[0] = p[0] = 0;
for (int mask = 0; mask < (1 << m); mask++){
for (int last = 0; last < m; last++){
if (!((1 << last) & mask))continue;
int previous = mask ^ (1 << last);
if (p[previous] == -1)continue;
int man = p[previous];
int money = f[previous] + b[last];
if (money < a[man]){
f[mask] = f[previous] + b[last];
p[mask] = man;
}
if (money == a[man]){
f[mask] = 0;
p[mask] = man + 1;
ok|=(man == n-1);
}
}
}
cout<<(ok?"YES":"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... |