# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758643 | KN200711 | Bank (IZhO14_bank) | C++14 | 191 ms | 12572 KiB |
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;
map<int, vector<int> > ck;
int nd[1000001];
set<int> dp[21];
int main() {
int N, M;
scanf("%d %d", &N, &M);
vector<int> A(N), B(M);
int sum1 = 0, sum2 = 0;
for(int i=0;i<N;i++) {
scanf("%d", &A[i]);
nd[A[i]] = 1;
sum1 += A[i];
}
for(int i=0;i<M;i++) {
scanf("%d", &B[i]);
sum2 += B[i];
}
if(sum1 > sum2) {
printf("NO\n");
return 0;
}
for(int i=0;i<(1 << M);i++) {
int sum = 0;
for(int k=0;k<M;k++) {
if(i&(1 << k)) sum += B[k];
}
if(sum <= 1e6 && nd[sum]) ck[sum].push_back(i);
}
dp[0].insert(0);
sort(A.begin(), A.end());
for(int i=0;i<N;i++) {
for(auto p : dp[i]) {
for(auto k : ck[A[i]]) {
if(p&k) continue;
dp[i + 1].insert(p|k);
}
}
}
if(dp[N].size()) printf("YES\n");
else printf("NO\n");
return 0;
}
Compilation message (stderr)
# | 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... |