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 <iostream>
#include <algorithm>
#include <vector>
#include <map>
using ll = long long;
using ld = long double;
const int inf = 1000 * 1000 * 1000 + 7;
using namespace std;
const int N = 207;
vector<int> a, b;
int ast = 0;
float st = 0;
map < pair<float, int>, bool> mp;
void rek() {
if (st == a.size() - 1&&a[st]==0) {
cout << "YES"; exit(0);
}
if (a[st] == 0) { st++; rek(); st--; }
if (mp[{ {st}, ast}] == true)return;
mp[{ {st}, ast}] = true;
for (int j = 0; j < b.size(); ++j) {
if (a[st] >= b[j]) {
if (b[j] > 0) {
int k = b[j];
a[st] -= k; b[j] -= k; ast += (1 << j);
rek();
a[st] += k; b[j] += k; ast -= (1 << j);
}
}
else break;
}
}
int main()
{
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
int k; cin >> k; a.push_back(k);
}
for (int i = 0; i < m; ++i) {
int k; cin >> k; b.push_back(k);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
rek();
cout << "NO" << endl;
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void rek()':
bank.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < b.size(); ++j) {
~~^~~~~~~~~~
# | 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... |