分析:
对于每个位置 找出当前高度 i i i 前后比 i i i 高的 用两边较矮的减去 i i i 就是水
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define reg register
using namespace std;
typedef long long ll;
const int N=5e4+5;
int n,a[N],b[N],c[N],ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=max(b[i-1],a[i]);
}
for(int i=n;i>=1;i--)
{
c[i]=max(c[i+1],a[i]);
ans+=min(b[i],c[i])-a[i];
}
printf("%d",ans);
return 0;
}