//
// main.cpp
// Number of moves
//
// Created by Himanshu on 19/09/21.
//
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
#define MAX 100
int solve (vector<int> nums) {
int sum = 0, minElement = INT_MAX, n = (int) nums.size();
for (int i=0; i<n; i++) {
minElement = min(minElement, nums[i]);
sum += nums[i];
}
return (sum - (n*minElement));
}
int main(int argc, const char * argv[]) {
vector<int> nums = {1, 2, 3};
printf("Number of moves to equalise array elements: %d\n", solve( nums));
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBOdW1iZXIgb2YgbW92ZXMKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMTkvMDkvMjEuCi8vCgoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y2xpbWl0cz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBNQVggMTAwCgoKaW50IHNvbHZlICh2ZWN0b3I8aW50PiBudW1zKSB7CiAgICBpbnQgc3VtID0gMCwgbWluRWxlbWVudCA9IElOVF9NQVgsIG4gPSAoaW50KSBudW1zLnNpemUoKTsKICAgIGZvciAoaW50IGk9MDsgaTxuOyBpKyspIHsKICAgICAgICBtaW5FbGVtZW50ID0gbWluKG1pbkVsZW1lbnQsICBudW1zW2ldKTsKICAgICAgICBzdW0gKz0gbnVtc1tpXTsKICAgIH0KICAgIAogICAgcmV0dXJuIChzdW0gLSAobiptaW5FbGVtZW50KSk7Cn0KCmludCBtYWluKGludCBhcmdjLCBjb25zdCBjaGFyICogYXJndltdKSB7CiAgICB2ZWN0b3I8aW50PiBudW1zID0gezEsIDIsIDN9OwogICAgcHJpbnRmKCJOdW1iZXIgb2YgbW92ZXMgdG8gZXF1YWxpc2UgYXJyYXkgZWxlbWVudHM6ICVkXG4iLCBzb2x2ZSggbnVtcykpOwogICAgcmV0dXJuIDA7Cn0K