题目描述
算法
package day;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class 积木大赛 {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String p[]=bufferedReader.readLine().split(" ");
int n=scanner.nextInt();
int a[]=new int [n+1];
for(int i=1;i<=n;i++){
a[i]=scanner.nextInt();
}
int res=0;
for(int i=1;i<=n;i++){
res+=Math.max(0, a[i]-a[i-1]);
}
System.out.println(res);
}
}