提交时间:2022-07-20 11:59:22

运行 ID: 52803

#include<bits/stdc++.h> #define upf(i,n,k) for(int i=k;i<=n;i++) #define lowf(i,n,k) for(int i=n;i>=k;i--) #define Max(a,b,c) max(a,max(b,c)) #define Min(a,b,c) min(a,min(b,c)) #define ofile(N) freopen(N".in","r",stdin),freopen(N".out","w",stdout) #define ri register int #define ie inline #define ll long long using namespace std; ie int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } ie void out(int a) { if(a>=10)out(a/10); putchar(a%10+'0'); } int n,a[112312],tmp,maxn[100010],ans; int main() { //ofile(""); n=read(); upf(i,n,1){ a[i]=read(); if(a[i]>tmp){ tmp=a[i]; maxn[i]=tmp; }else maxn[i]=maxn[i-1]; } // upf(i,n,1) { // int j=i+1; // upf(j,n,i+1)+ // if(a[i]>a[j]) { // maxn[j]=a[i]; // cout<<maxn[j]<<' '; // ans+=a[i]-a[j]; // cout<<a[i]-a[j]; // }else i=j; // } // upf(i,n,1)ans+=maxn[i]-a[i]; upf(i,n,1)ans+=maxn[i]-a[i]; cout<<ans; return 0; }