【2018】

T1.铺设道路(模拟)

肯定要挖至少第一个坑的深度,再把后面比现在的坑的最深深度深的差值加起来,更新现在坑得最深深度(因为比现在最深深度浅的可以和之前的一起一次性处理,只用多花时间填更深的差值)。

#include<bits/stdc++.h>
#define ll long long
#define ri register int 
#define For(i,l,r) for(ri i=l;i<=r;i++)
#define Dfor(i,r,l) for(ri i=r;i>=l;i--)
using namespace std;
int n,d,tmp;
ll ans;
inline ll read(){
    ll f=1,sum=0;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){sum=(sum<<1)+(sum<<3)+(ch^48);ch=getchar();}
    return f*sum;
}
int main(){
    n=read();
    For(i,1,n){
        d=read();
        if(d>tmp) ans+=d-tmp;
        tmp=d;
    }
    printf("%lld\n",ans);
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/jian-song/p/11837834.html