이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
#define ll long long
void solve() {
// covered[mask] = max prefix of people that we can pay
// leftover[mask] = amount of money left over after we pay off the people
int n, m; cin >> n >> m;
vector<int> covered(1 << m, 0), leftover(1 << m, 0);
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int subset = 1; subset < (1 << m); subset++) {
for (int bit = 0; bit < m; bit++) {
if (subset & (1 << bit)) {
int prev = subset ^ (1 << bit);
int next = covered[prev];
int left = leftover[prev];
if (next == n) continue;
if (a[next] == left + b[bit]) {
covered[subset] = max(covered[subset], next + 1);
if (covered[subset] == next + 1) {
leftover[subset] = 0;
}
} else {
leftover[subset] += b[bit];
}
}
}
}
for (int subset = 1; subset < (1 << m); subset++) {
if (covered[subset] == n) {
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)
solve();
}
# | 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... |