Preview:
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long  //always use this 

int main()
{   
    const  int mxN = 2e5; //to make a maximum array
    int n ,  m ,k, a[mxN], b[mxN];
    cin>>n>>m>>k;
    for(int i =0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i =0;i<m;i++)
    {
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b , b+m);
    int ans = 0;
    for(int i =0 , j =0 ;i<n;i++)
    {
        while(j<m && b[j]<a[i]-k)
              j++;
        if(j<m && b[j]<=a[i]+k)   //all logic in it 
             ans++, j++;
    }
    cout<<ans;
    
    
    
    
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter