Advertisement
Josif_tepe

Untitled

Jun 2nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   int a;
  10.   int b;
  11.   int c;
  12.   cin>>a>>b>>c;
  13.   vector<int>v;
  14.   vector<int>v2;
  15.   for(int y=0; y<a; y++){
  16.    int y1;
  17.    cin>>y1;
  18.    v.push_back(y1);
  19.   }
  20.  
  21.   for(int y2=0; y2<b; y2++){
  22.    int y3;
  23.    cin>>y3;
  24.    v2.push_back(y3);
  25.   }
  26.   sort(v.begin(),v.end());
  27.   sort(v2.begin(),v2.end());
  28.  
  29.   int i=0;
  30.   int j=0;
  31.  
  32.   int brojac=0;
  33.   while((i<a)and(j<b)){
  34.   if(abs(v[i]-v2[j])<=c){
  35.    brojac+=1;
  36.    i+=1;
  37.    j+=1;
  38.   }
  39.   else {
  40.     if(v[i]>v2[j]){
  41.     j+=1;
  42.     }
  43.     else if(v[i]<v2[j]){
  44.         i+=1;
  45.     }
  46.   }
  47.   }
  48.   cout<<brojac;
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement