Apartments problem from CSES problem set

Why does my code give correct answer only for half the test cases?

#include<bits/stdc++.h>

using namespace std;

int main(){

int n,m;
unsigned long long k;
cin>>n>>m>>k;
vector<unsigned long long> desired(n);
for(int i=0;i<n;i++){
    cin>>desired[i];
}
vector<unsigned long long> available(m);
for(int i=0;i<m;i++){
    cin>>available[i];
}
int ans=0;
unordered_map<unsigned long long, int> mp;
for(int i=0;i<m;i++){
    mp[available[i]]++;
}
for(int i=0;i<n;i++){
    for(long long j =desired[i]-k ; j<= desired[i]+k ; j++ ){
        auto it = mp.find(j);
        if(it!=mp.end()){
            if(it->second!=0){
                ans++;
                it->second=(it->second)-1;
                break;
            }
        }
    }
}
cout<<ans<<endl;

return 0;

}