QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#807442 | #9873. Last Chance: Threads of Despair | Wzy# | WA | 1ms | 3868kb | C++14 | 1.2kb | 2024-12-09 23:34:02 | 2024-12-09 23:34:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const int N=2e5+10,M=2e6;
const int mod=998244353;
const LL P=1e9+7;
const LL INF=1e18;
LL h[N],e[M],ne[M],w[M],idx;
int n;
void solve(){
int n,m;
cin>>n>>m;
int cnt=0,nw=0;
vector<PII> a;
bool fg=false;
for(int i=0;i<n;i++){
int x;
cin>>x;
if(x>1) cnt++,x--;
if(x==1&&!fg) fg=true,cnt++;
a.push_back({x,0});
}
for(int i=0;i<m;i++){
int x;
cin>>x;
a.push_back({x,1});
}
sort(a.begin(),a.end());
bool sg=true;
multiset<int> st;
for(auto [x,y]:a){
if(x==1) nw++;
else if(y){
if(x<=nw) nw++;
else if(x-nw<=cnt) cnt-=x-nw,nw++;
else sg=false;
while(st.size()!=0&&*st.begin()<=nw) nw++,st.erase(st.begin());
}
else {
if(nw>=x) nw++;
else st.insert(x);
}
}
if(sg) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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: 1ms
memory: 3632kb
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: 3868kb
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 Yes Yes
result:
wrong answer expected NO, found YES [2nd token]