# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085797 | Sunbae | Bank (IZhO14_bank) | C++17 | 87 ms | 8612 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>
const int inf = 2e8;
using namespace std;
int a[20], b[20], dp[1<<20], l[1<<20];
signed main(){
int n, m; scanf("%d %d", &n, &m);
for(int i = 0; i<n; ++i) scanf("%d", a+i);
for(int i = 0; i<m; ++i) scanf("%d", b+i);
int lim = 1<<m;
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for(int mk = 0; mk<lim; ++mk){
for(int i = 0; i<m; ++i){
if(mk>>i&1){
int pmk = mk ^ (1<<i);
if(dp[pmk] != -1 && b[i] + l[pmk] == a[dp[pmk]]){
dp[mk] = max(dp[mk], dp[pmk] + 1);
l[mk] = 0;
}else if(dp[pmk] != -1 && b[i] + l[pmk] < a[dp[pmk]]){
dp[mk] = max(dp[mk], dp[pmk]);
l[mk] = b[i] + l[pmk];
}
}
}
}
(*max_element(dp, dp+lim) == n) ? puts("YES") : puts("NO");
}
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... |