Most of the students of the law school prefer visiting photo club to the competitions in Roman law. Members of the photo club visit different interesting places, take photos of each other in front of them, and then rate their photos.
Once they appeared on a unbelievably long street which had n buildings in a row. Every member of the photo club took a photo contained, besides the members of the club and people passing by, a segment of the street. In other words, if you number the buildings in the order they are located on the street, each photo contained some buildings with the consecutive numbers.
Some day a Roman law professor of that law school came across the exhibition of the photos from that street. He hasn't remembered how many photos were there, but he has noticed that the i-th building was captured on ai photos. Now he wants to estimate the minimal number of his students in the photo club, considering that no one could present more that one photo at the exhibition.
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of buildings.
The second line contains n space-separated integers: ai (0 ≤ ai ≤ 109) — the number of photos that contain the i-th building.
Output a single integer — the minimal number of students in the photo club.
4 1 3 2 0
3
6 1 2 3 1 2 3
5
第一次打codeforces的gym,金桔和标神抓的题,一场简单的gym,这个题的意思是有n张照片,照片上是些连续的序号,现在告诉你每个序号被多少照片照过,求最少多少人,一个人只照一张。
一个思维规律题,看看和前面一个数的差值,这个题就水过了。。。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
int a[300000];
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
LL ans=0;
ans+=a[0];
for(int i=1;i<n;i++){
if(a[i]-a[i-1]>0){
ans+=(LL)(a[i]-a[i-1]);
}
}
cout<<ans<<endl;
}
return 0;
}