1074 - Stick Lengths
28 Jan 2021 — Tags: None
Click to show code.
using namespace std;
using ll = long long;
using vll = vector<ll>;
int main(void)
{
int n;
cin >> n;
vll p(n);
for (auto &pi : p)
cin >> pi;
sort(p.begin(), p.end());
int pivot = p[n / 2];
cout << accumulate(p.begin(), p.end(), 0LL, [pivot](ll acc, ll x) {
return acc + abs(pivot - x);
}) << endl;
return 0;
}