aboutsummaryrefslogtreecommitdiff
path: root/02_sorting_and_searching/stick_lengths_1074.cpp
blob: e41a7d8e53e91428fcf3116c173d15b786ddbe55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
	long long n;
	std::cin >> n;
	std::vector<long long> a(n);
	for (long long i = 0; i < n; i++)
		std::cin >> a[i];
	std::sort(a.begin(), a.end());
	long long s{0}, t{a[n/2]};
	for (auto x : a)
		s += std::abs(x-t);
	std::cout << s << "\n";
}

Generated with cgit - Back to sebastiano.tronto.net