QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#808590 | #9873. Last Chance: Threads of Despair | shengZzz | WA | 2ms | 5688kb | C++20 | 1.6kb | 2024-12-10 21:46:15 | 2024-12-10 21:46:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int h1[N], h2[N];
void solve(){
int n, m; cin >> n >> m;
for(int i = 0 ; i < n; ++i)
cin >> h1[i];
for(int i = 0 ; i < m ; ++i)
cin >> h2[i];
sort(h1, h1 + n);
sort(h2, h2 + m);
int ex = 0, att = 0,idx=0;
for(int i = 0 ; i < n ; ++i){
if(h1[i] == 1){
att=1;
idx=i;
++ex;
}
else ++att;
}
int i = idx, j = 0;
if(ex>0) --ex;
int flag = 0;
while(i < n && j < m){
while((i<n && h1[i]-1<=ex) || (j<m && h2[j]<=ex)){
while(i<n && h1[i]-1<=ex){
++i;
++ex;
}
while(j<m && h2[j]<=ex){
++j;
++ex;
}
}
// cout<<"i=="<<i<<" j=="<<j<<endl;
// cout<<"ex=="<<ex<<endl;
// cout<<"att=="<<att<<endl;
while(j<m && att>=h2[j]-ex){
att-=(h2[j]-ex);
ex++;
j++;
}
if(flag>10000){
cout<<"NO"<<"\n";
return;
}
else if(att<h2[j]-ex){
flag++;
}
}
if(j>=m) cout<<"YES"<<"\n";
else cout<<"NO"<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
solve();
}
}
/*
1
5 2
3 4 5 6 7
1 6
3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2
1
3 2
1 1 4
2 7
1
2 1
100 100
2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
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: 1ms
memory: 5680kb
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: 1ms
memory: 5616kb
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: 0
Accepted
time: 0ms
memory: 5620kb
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 YES YES NO NO YES YES NO NO NO NO YES NO NO NO NO NO
result:
ok 18 token(s): yes count is 7, no count is 11
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
18 2 1 1 1 1 2 1 1 1 2 2 1 1 1 3 2 1 1 2 1 2 1 2 1 2 2 1 2 1 3 2 1 1 3 1 2 1 1 3 2 2 1 3 1 3 2 1 2 2 1 2 1 2 2 2 2 1 2 2 3 2 1 2 3 1 2 1 3 2 2 2 1 2 3 3 2 1 3 3 1 2 1 3 3 2 2 1 3 3 3
output:
YES YES YES YES YES YES YES YES YES YES YES NO YES YES NO YES YES NO
result:
ok 18 token(s): yes count is 15, no count is 3
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 5632kb
input:
525 2 3 1 1 1 1 1 2 3 1 1 1 2 1 2 3 1 1 1 3 1 2 3 1 1 1 4 1 2 3 1 1 5 1 1 2 3 1 1 2 2 1 2 3 1 1 3 1 2 2 3 1 1 1 2 4 2 3 1 1 2 1 5 2 3 1 1 3 3 1 2 3 1 1 4 3 1 2 3 1 1 3 5 1 2 3 1 1 4 4 1 2 3 1 1 4 5 1 2 3 1 1 1 5 5 2 3 1 1 2 2 2 2 3 1 1 2 3 2 2 3 1 1 2 2 4 2 3 1 1 2 5 2 2 3 1 1 3 2 3 2 3 1 1 3 2 4 2 ...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES YES YES YES YES YES NO NO YES YES NO NO NO NO NO NO NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES NO NO NO NO NO NO YES YES YES YES YES YES YES YES YES YES ...
result:
wrong answer expected YES, found NO [92nd token]