QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#809110 | #9873. Last Chance: Threads of Despair | proven | WA | 0ms | 3816kb | C++20 | 1.4kb | 2024-12-11 11:45:50 | 2024-12-11 11:45:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(m + 1);
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= m;i++) cin >> b[i];
sort(a.begin() + 1, a.end());
sort(b.begin() + 1, b.end());
int a1 = 0, b1 = 0;
for(int i = 1;i <= n;i++) {
a1 += (a[i] == 1);
}
for(int i = 1;i <= m;i++) {
b1 += (b[i] == 1);
}
int cnt = (a1 != 0);
for(int i = 1;i <= n;i++) {
if(a[i] > 1) cnt++, a[i]--;
}
int now = a1, flag = 0;
if(b1) {
cnt--;
now += b1;
flag = 1;
}
int k = 1;
while(k <= n && a[k] == 1) k++;
for(int i = 1;i <= m;i++) {
if(b[i] == 1) {
continue;
}
while(k <= n && a[k] <= now) {
k++;
now++;
}
int num = b[i] - now;
if(num <= 0) now++, flag = 1;
else {
if(cnt < num) {
cout << "No" << endl;
return;
}
now++;
cnt -= num;
flag = 1;
}
}
cout << "Yes" << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
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: 3816kb
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: 0
Accepted
time: 0ms
memory: 3492kb
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 Yes
result:
ok 3 token(s): yes count is 1, no count is 2
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
4 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 2
output:
Yes Yes Yes No
result:
ok 4 token(s): yes count is 3, no count is 1
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
18 1 2 1 1 1 1 2 1 2 1 1 2 1 1 3 1 2 1 2 2 1 2 1 3 2 1 2 1 3 3 1 2 2 1 1 1 2 2 1 2 1 2 2 1 3 1 2 2 2 2 1 2 2 2 3 1 2 2 3 3 1 2 3 1 1 1 2 3 1 2 1 2 3 1 3 1 2 3 2 2 1 2 3 3 2 1 2 3 3 3
output:
Yes Yes No Yes No No Yes No No No No No Yes No No No No No
result:
wrong answer expected YES, found NO [3rd token]