QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#808623 | #9873. Last Chance: Threads of Despair | Jun666 | WA | 1ms | 3660kb | C++20 | 2.4kb | 2024-12-10 22:26:36 | 2024-12-10 22:26:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n,m;
cin>>n>>m;
vector<int>l(n),r(m);
vector<int>d(n+m,1);
int cnt=0;
for(int i=0;i<n;i++){
cin>>l[i];
if(l[i]>1){
cnt++;
l[i]-=1;
}
}
for(int i=0;i<m;i++){
cin>>r[i];
}
sort(l.begin(),l.end());
sort(r.begin(),r.end());
for(int i=2;i<n+m;i++){
d[i]+=d[i-1];
}
int a=0,b=0,c=0;
if(l[a]!=1){
if(cnt>=max(r[b],0ll)){
cnt-=max(r[b],0ll);
b++;
c++;
}else{
cout<<"No"<<"\n";
return ;
}
}else{
cnt++;
a++;
c++;
}
while(a<n&&b<m){
if(l[a]<=r[b]){
// cout<<"***"<<'\n';
if(l[a]<=d[c]){
a++;
c++;
}else{
if(r[b]-d[c]<=cnt){
cnt-=(r[b]-d[c]);
b++;
c++;
}else{
cout<<"No"<<"\n";
return ;
}
}
}else{
if(r[b]<=d[c]){
b++;
c++;
}else{
if(r[b]-d[c]<=cnt){
cnt-=(r[b]-d[c]);
b++;
c++;
}else{
cout<<"No"<<"\n";
return ;
}
}
}
// cout<<b<<'\n';
}
while(b<m){
if(r[b]<=d[c]){
b++;
c++;
}else if(r[b]-d[c]<=cnt){
cnt-=(r[b]-d[c]);
b++;
c++;
}else{
cout<<"No"<<"\n";
return ;
}
}
cout<<"Yes"<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
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: 3572kb
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: -100
Wrong Answer
time: 1ms
memory: 3660kb
input:
4 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 2
output:
Yes Yes Yes Yes
result:
wrong answer expected NO, found YES [4th token]