# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1131386 | ahmedsahlol | Bank (IZhO14_bank) | C++20 | 314 ms | 114532 KiB |
#include <bits/stdc++.h>
#define int long long
#define el '\n'
using namespace std;
void work() {
int n, m;
cin >> n >> m;
vector<int> v(n);
for (auto &i: v)cin >> i;
sort(v.begin(), v.end());
priority_queue<int> pq, extra;
for (int i = 1, a; i <= m; ++i) {
cin >> a;
pq.push(a);
}
for (int i = 0; i < n; ++i) {
while (pq.size() && v[i] > 0) {
int now = pq.top();
pq.pop();
if (v[i] >= now) {
v[i] -= now;
} else {
extra.push(now);
}
}
if (v[i] > 0) {
cout << "NO" << el;
return;
}
while (extra.size()) {
pq.push(extra.top());
extra.pop();
}
}
cout << "YES" << el;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("D:\\Work\\input.txt", "r", stdin);
freopen("D:\\Work\\output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc = 1;
// cin >> tc;
while (tc--) {
work();
}
}
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... |