```
class Solution {
public:
int minMoves(vector<int>& nums) {
int moves = 0;
int minVal = INT_MAX;
for (int i = 0; i < nums.size(); i++) {
if (minVal > nums[i]) {
moves += (minVal - nums[i]) * i;
minVal = nums[i];
}
else {
moves += nums[i] - minVal;
}
}
return moves;
}
};
```