Advertisement
Josif_tepe

Untitled

Jun 1st, 2024
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     long long niza[n];
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> niza[i];
  12.     }
  13.     sort(niza, niza + n);
  14.     long long medijana = niza[n / 2];
  15.     long long rez = 0;
  16.     for(int i = 0; i < n; i++) {
  17.         rez += abs(medijana - niza[i]);
  18.     }
  19.     cout << rez << endl;
  20.      return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement