Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
141827 mairuisheng 收集雨水 C++ 通过 100 1 MS 292 KB 545 2024-04-06 11:30:50

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int main() { int n,a[11000],l,r,ans=0; cin>>n; for (int i=1;i<=n;i++) cin>>a[i]; l=1;while (a[l]==0) l++; r=n;while (a[r]==0) r--; int tmp=0,j=l,k=l+1; while (k<=r+1) if (a[k]<a[j]) { tmp+=a[k]; k++; } else { ans+=(k-j-1)*a[j]-tmp; tmp=0; j=k; k++; } tmp=0;j=r;k=r-1; while (k>=l-1) if (a[k]<=a[j]) { tmp+=a[k]; k--; } else { ans+=(j-k-1)*a[j]-tmp; tmp=0; j=k; k--; } cout<<ans; return 0; }


测评信息: