# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
555808 | Alma | Bank (IZhO14_bank) | C++17 | 88 ms | 8488 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;
#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;
const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;
void setIO (string fileName) {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fileName != "std") {
freopen((fileName + ".in").c_str(), "r", stdin);
freopen((fileName + ".out").c_str(), "w", stdout);
}
}
int N, M;
int a[20], b[20], pre[20];
int idx[(1 << 20)], dp[(1 << 20)];
int main() {
setIO("std");
memset(pre, 0, sizeof pre);
memset(dp, -1, sizeof dp);
dp[0] = 0;
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> a[i];
if (i == 0) pre[i] = a[i];
else pre[i] = a[i] + pre[i-1];
}
for (int i = 0; i < M; i++) {
cin >> b[i];
}
for (int mask = 1; mask < (1 << M); mask++) {
for (int i = 0; i < M; i++) {
if (!(mask & (1 << i))) continue;
int x = mask - (1 << i);
if (dp[x] == pre[idx[x]]) {
dp[mask] = dp[x] + b[i];
idx[mask] = idx[x] + 1;
}
else if (dp[x] + b[i] <= pre[idx[x]]) {
dp[mask] = dp[x] + b[i];
idx[mask] = idx[x];
}
}
}
for (int mask = 0; mask < (1 << M); mask++) {
if (dp[mask] == pre[N-1]) {
cout << "YES\n";
return 0;
}
}
cout << "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... |