-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1859.java
42 lines (36 loc) · 1.01 KB
/
p1859.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package self.samsungExpert;
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;
// platform | SW Expert Academy
// number | 1859
// title | 백만 장자 프로젝트
// level | D2
// how |
// etc |
// result |
public class p1859 {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++) {
int n = sc.nextInt();
int[] pay = new int[n];
for(int i=0; i<n; ++i) {
pay[i] = sc.nextInt();
}
long sum = 0;
int max = 0;
for(int i=n-1; i>=0; --i) {
if(max<pay[i]) {
max = pay[i];
}
else {
int mg = max - pay[i];
sum+=mg;
}
}
System.out.printf("#%d %d%n", test_case, sum);
}
}
}