Solution to the problem number 589 of AceptaelReto - 589.

Any questions do not hesitate to contact.


#include <bits/stdc++.h>
using namespace std;

//No es necesaria una estructura de datos para resolver
//En caso de almacenar todas las copas, dará MLE

int main(){
    int n;
    while(scanf("%d",&n) == 1 && n!=0){
        long long int curMaxValue = 0,number,res=0;
        for(int i=0; i<n;i++) {
            scanf("%lld",&number);
            if(number>curMaxValue) {
                res+=(number-curMaxValue)*i;
                curMaxValue=number;
            }
            else{
                res+=curMaxValue-number;
            }
        }
        printf("%lld\n",res);
    }
    return 0;
}

Don't miss anything.

Keep in touch with Isaac Lozano Osorio!