import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); //这里直接用贪心 当后边的数比前面大就直接买进然后卖出再买进再对比 int cur =0,pre=1000000; int n = in.nextInt(); int ret=0; while(n-->0){ cur = in.nextInt(); if(cur>pre){ ret+=cur-pre; } pre = cur; } System.out.print(ret); } }