Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
119520 | 陈家宝 | 收集雨水 | C++ | 通过 | 100 | 2 MS | 292 KB | 497 | 2024-01-08 13:06:32 |
#include<bits/stdc++.h> using namespace std; int main() { int n,a[11000],l,r,cnt=0; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; l=1; r=n; int tmp=0,j=l,k=l+1; while(k<=r+1){ if(a[k]<a[j]){ tmp+=a[k]; k++; } else{ cnt+=(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{ cnt+=(j-k-1)*a[j]-tmp; tmp=0; j=k; k--; } } cout<<cnt; return 0; }