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 <fstream>
#include <iostream>
using namespace std;
int n, m;
int a[21];
int b[21];
int dp[(1 << 20)];
int sum[(1 << 20)];
bool ok;
void read() {
int i;
ifstream f("bank.in");
f >> n >> m;
for (i = 0; i < n; i++)
f >> a[i];
for (i = 0; i < m; i++)
f >> b[i];
f.close();
}
void solve() {
int i, j;
dp[0] = 0;
for (i = 0; i < (1 << m) && !ok; i++) {
for (j = 0; j < m && !ok; j++) {
if (i & (1 << j))
continue;
if (sum[i] + b[j] < a[dp[i]] && dp[i] >= dp[i | (1 << j)]) {
sum[i | (1 << j)] = sum[i] + b[j];
dp[i | (1 << j)] = dp[i];
}
else if (sum[i] + b[j] == a[dp[i]] && dp[i] + 1 > dp[i | (1 << j)]) {
dp[i | (1 << j)] = dp[i] + 1;
if (dp[i | (1 << j)] == n)
ok = 1;
sum[i | (1 << j)] = 0;
}
}
}
}
void output() {
ofstream g("bank.out");
g << (ok == 1 ? "YES\n" : "NO\n");
g.close();
}
int main() {
read();
solve();
output();
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... |