#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Jieyushui{
public : int jie(){
int i;
//获取int数组v
vector<int> v;
int num = 0;
do {
cin >> num;
v.push_back(num);
} while (getchar() != '\n');
int sum=0;
int zuo_feng=0;
int you_feng=0;
int max_feng=0;
int zuo_biao=0;
int you_biao=0;
int max_biao=0;
int len=v.size();
bool flag=0;
//找到左,最高,右峰值和它们的下标
//左锋下标
for(i=0;i<len-1;i++){
if(v[i]<=v[i+1]){
zuo_feng=v[i+1];
}else{
zuo_feng=v[i];
break;
}
}
zuo_biao=i;
cout<<"zuo_biao="<<zuo_biao<<endl;
//最高峰下标
max_feng=v[0];
for(i=0;i<len;i++){
flag=0;
if(max_feng<v[i]){
max_feng=v[i];
flag=1;
}
if(flag){
max_biao=i;
}
}
cout<<"max_biao="<<max_biao<<endl;
//右锋下标
for(i=len-1;i>0;i--){
if(v[i]<=v[i-1]){
you_feng=v[i-1];
}else{
you_feng=v[i];
break;
}
}
you_biao=i;
cout<<"you_biao="<<you_biao<<endl;
//左边累加
for(i=zuo_biao;i<max_biao;i++){
if(zuo_feng>v[i]){
sum+=zuo_feng-v[i];
}
else{
zuo_feng=v[i];
}
}
//右边累加
for(i=you_biao;i>max_biao;i--){
if(you_feng>v[i]){
sum+=you_feng-v[i];
}
else{
you_feng=v[i];
}
}
cout<<"sum="<<sum<<endl;
return 0;
}
};
int main(){
Jieyushui j;
j.jie();
system("pause");
return 0;
}