- 这是dp吗。。。。。这就纯贪心吧
- 如果任何一天比前一天价格高,就在前一天买入今天卖,完事了
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
int n = nextInt();
int[] list = new int[n];
for (int i = 0; i < list.length; i++) {
list[i] = nextInt();
}
int sum = 0;
for (int i = 1; i < n; i++) {
if(list[i]>list[i-1])
sum += (list[i]-list[i-1]);
}
System.out.println(sum);
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(br);
static int nextInt() throws IOException {
st.nextToken();
return (int)st.nval;
}
}