提交时间:2022-07-20 11:58:01
运行 ID: 52791
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } int main() { ll n,ans=0; n=read(); ll a[n+1]; for(ll i=1; i<=n; i++) { a[i]=read(); } for(int i=n; i>=2; i--) { int max=a[i]; for(int j=i-1; j>=1; j--) { if(max<a[j]) { max=a[j]; } } ans+=(max-a[i]); } printf("%lld",ans); return 0; }