QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#838803 | #9873. Last Chance: Threads of Despair | TangWK | WA | 0ms | 3628kb | C++20 | 2.4kb | 2024-12-31 23:16:01 | 2024-12-31 23:16:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(m + 1);
priority_queue<int, vector<int>, greater<int>> q1, q2;
int bump = 0, damage = 0;
bool flag = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] > 1) {
++damage;
}else if (a[i] == 1) {
if (!flag) {
++damage;
flag = true;
}
}
q2.push(a[i] - 1);
}
for (int i = 1; i <= m; ++i) {
cin >> b[i];
q1.push(b[i]);
}
while (damage > 0) {
flag = false;
while (!q1.empty() && q1.top() <= bump) {
q1.pop();
++bump;
flag = true;
}
// cout << "!!!\n";
while (!q2.empty() && q2.top() <= bump) {
q2.pop();
++bump;
flag = true;
}
if (!q1.empty()) {
// int tmp_damage = min(damage, q1.top() - bump);
if (q1.top() <= bump) {
q1.pop();
++bump;
continue;
flag = true;
}else {
// int tmp = min(damage, q1.top() - bump);
if (q1.top() - bump > damage) {
break;
}
damage -= q1.top() - bump;
q1.pop();
// damage -= tmp;
// q1.push();
}
}
if (!flag) {
break;
}
}
while (!q1.empty() && !q2.empty()) {
flag = false;
while (!q1.empty() && q1.top() <= bump) {
++bump;
q1.pop();
flag = true;
}
while (!q2.empty() && q2.top() <= bump) {
++bump;
q2.pop();
flag = true;
}
if (!flag) {
break;
}
}
while (!q1.empty() && q1.top() <= bump) {
++bump;
q1.pop();
}
if (!q1.empty()) {
// cout << q1.top() << "??\n";
// cout << bump << "Qwq\n";
// cout << damage << "??\n";
cout << "No\n";
}else {
cout << "Yes\n";
}
return;
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 3 2 1 1 4 2 6 3 2 1 1 4 2 7 2 1 100 100 2
output:
Yes No Yes
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
3 7 1 1 1 1 1 1 1 1 9 5 2 3 4 5 6 7 1 6 5 3 3 4 5 6 7 1 5 7
output:
No No No
result:
wrong answer expected YES, found NO [3rd token]