fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. cout.tie(NULL);
  8. int long long n,k,q,mini,maxi,t,last,dif,m,cnt=0,ans=0,ne=0,x,y;
  9. bool flag;
  10. //string s;
  11. cin>>n>>m>>x>>y;
  12. int long long arr[n],b[m];
  13. map<int long long,int long long>mp;
  14. for(int i=0;i<n;i++)
  15. cin>>arr[i];
  16. for(int i=0;i<m;i++)
  17. cin>>b[i];
  18. cnt=0;
  19. for(int i=0;i<n;i++)
  20. {
  21.  
  22. while(cnt<m && b[cnt]<arr[i]-x)
  23. cnt++;
  24. if(cnt==m)
  25. break;
  26. if(b[cnt]>= arr[i]-x && b[cnt]<=arr[i]+y)
  27. {
  28. ans++;
  29. mp[i+1]=cnt+1;
  30. cnt++;
  31. continue;
  32. }
  33. }
  34. cout<<ans<<endl;
  35. if(ans>0)
  36. for(auto it=mp.begin();it!=mp.end();it++)
  37. {
  38. cout<<it->first<<" "<<it->second<<endl;
  39. }
  40.  
  41. }
Success #stdin #stdout 0s 4368KB
stdin
5 3 0 0
1 2 3 3 4
1 3 5
stdout
2
1 1
3 2