include iostream include algorithm include vector using namespace std

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <algorithm>
#include <vector>
//using namespace std;
int rast(std::vector<int> mas, int station)
{
int sum = 0;
for (int i = 0; i < mas.size(); i++)
{
if (i != station)
sum += abs(mas[station] - mas[i]);
}
return sum;
}
int main()
{
int n;
std::cin >> n;
std::vector<int> mas;
for (int i = 0; i < n; i++)
{
int buf;
std::cin >> buf;
mas.push_back(buf);
}
sort(mas.begin(), mas.end());
int station = 0;
int way = rast(mas, 0);
for (int i = 1; i < mas.size(); i++)
{
int sum = rast(mas, i);
if (sum < way)
{
station = i;
way = sum;
}
};
std::cout << mas[station];
return 0;
}