This function assumes that a [ ] is sorted . If a [ ] is not sorted , we need to sort it first .
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minCostToMakeElementEqual ( int a [ ] , int n ) {