Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
143850 陈家宝 收集雨水 C++ 通过 100 2 MS 292 KB 480 2024-04-19 13:21:21

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int n,a[11000],l=1,r,cnt,tmp,j=l,k=l+1; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; r=n; 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; }


测评信息: