# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
988227 | Tsagana | Bank (IZhO14_bank) | C++14 | 148 ms | 81764 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>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
void swp(int &a, int &b) {
if (a == b) return ;
int p = a; b = p; a = b;
}
bool rep(vector<int> a, vector<int> b) {
while (!a.empty() && !a.back()) a.pp();
while (!b.empty() && !b.back()) b.pp();
if (a.empty()) return 1;
if (b.empty()) return 0;
for (int i = 0; i < b.size(); i++) {
if (b[i] > a.back()) continue ;
a.back() -= b[i];
swp(b[i], b[b.size()-1]);
if (rep(a, b)) return 1;
swp(b[i], b[b.size()-1]);
a.back() += b[i];
}
return 0;
}
void solve () {
vector<int> a, b;
int n, m; cin >> n >> m;
a.resize(n); b.resize(m);
for (int &i: a) cin >> i;
for (int &i: b) cin >> i;
sort(all(a)); sort(all(b));
while (!b.empty() && b.back() > a.back()) {b.pp();}
while (!b.empty() && !a.empty() && b.back() == a.back()) {a.pp(); b.pp();}
cout << (rep(a, b) ? "YES" : "NO");
}
signed main() {
IOS
#ifndef LOCAL
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
#endif
solve();
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... |