CSES - Stick Lengths

Author: Danh Ta Chi Thanh

In this problem, we are given an array with nn elements. We want to find the minimum cost to make all of the elements equal.

Solution

Unofficial Editorial

Another solution and some proofs

Here is the code implemenation for the easiest approach.

#include <bits/stdc++.h>
using namespace std;
//variables used for the current problem
int n,median;
vector<int> p;
long long ans,cnt;
void solve() {

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!