Advertisement
Josif_tepe

Untitled

Jun 10th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1.     #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int k;
  9. vector<int>v;
  10. cin>>k;
  11. long long zbir=0;
  12. for(int k1=0; k1<k; k1++){
  13.     int x;
  14.     cin>>x;
  15.     v.push_back(x);
  16. }
  17.  
  18. sort(v.begin(),v.end());
  19. int medijan=v[k/2];
  20.  
  21. for(int k2=0; k2<k; k2++){
  22.     if(v[k2]>medijan){
  23.      zbir+=v[k2]-medijan;
  24.     }
  25.     if(v[k2]<medijan){
  26.      zbir+=medijan-v[k2];
  27.     }
  28. }
  29. cout<<zbir;
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement