analysys
DP
设 f [ i ] f[i] f[i]为填满1~i需要的天数
则
当
d
[
i
]
<
d
[
i
−
1
]
时
,
f
[
i
]
=
f
[
i
−
1
]
当
d
[
i
]
>
d
[
i
−
1
]
时
,
f
[
i
]
=
f
[
i
−
1
]
+
d
[
i
]
−
d
[
i
−
1
]
当d[i]<d[i-1]时,f[i]=f[i-1]\\当d[i]>d[i-1]时,f[i]=f[i-1]+d[i]-d[i-1]
当d[i]<d[i−1]时,f[i]=f[i−1]当d[i]>d[i−1]时,f[i]=f[i−1]+d[i]−d[i−1]
code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,start,end) for(register int i=start;i<=end;++i)
template<typename T>void read(T &x){
x=0;char r=getchar();T neg=1;
while(r>'9'||r<'0'){if(r=='-')neg=-1;r=getchar();}
while(r>='0'&&r<='9'){x=(x<<1)+(x<<3)+r-'0';r=getchar();}
x*=neg;
}
const int maxn=100000+10;
int d[maxn],n;
ll dp[maxn];
int main(){
read(n);
loop(i,1,n)read(d[i]);
loop(i,1,n){
if(d[i]<=d[i-1])dp[i]=dp[i-1];
else if(d[i]>d[i-1])dp[i]=dp[i-1]+d[i]-d[i-1];
}printf("%lld\n",dp[n]);
return 0;
}