Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- int k;
- vector<int>v;
- cin>>k;
- long long zbir=0;
- for(int k1=0; k1<k; k1++){
- int x;
- cin>>x;
- v.push_back(x);
- }
- sort(v.begin(),v.end());
- int medijan=v[k/2];
- for(int k2=0; k2<k; k2++){
- if(v[k2]>medijan){
- zbir+=v[k2]-medijan;
- }
- if(v[k2]<medijan){
- zbir+=medijan-v[k2];
- }
- }
- cout<<zbir;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement