题目描述
分析
这道题貌似很水啊,应该不难才对
真搞不懂NOIP提高组是不是真的普及组+省选
首先从小到大排序,然后再一个一个的枚举,到每一位按原来的位置向两边扩散,遇到0就停止。轻松自然
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
int h,w;
}a[100001];
int n,i,ans,j,x,s,b[100001];
bool cmp(node x,node y){return x.h<y.h;}
int main()
{
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&a[i].h);
a[i].w=i;
b[i]=a[i].h;
}
sort(a+1,a+n+1,cmp);
for (i=1;i<=n;i++)
{
x=a[i].w;
s=b[a[i].w];
for (j=x;j>=1;j--)
{
if (b[j]>0) b[j]-=s;
else break;
}
for (j=x+1;j<=n;j++)
{
if (b[j]>0) b[j]-=s;
else break;
}
ans+=s;
}
printf("%d",ans);
}
别想copy