Solution
Another solution and some proofs
Implementation
Time Complexity:
n = int(input())sticks = sorted(list(map(int, input().split())))median = sticks[n // 2]ans = 0for x in sticks:ans += abs(median - x)print(ans)
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!