forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe1859.java
More file actions
53 lines (34 loc) · 881 Bytes
/
swe1859.java
File metadata and controls
53 lines (34 loc) · 881 Bytes
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
43
44
45
46
47
48
49
50
51
52
53
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
public class swe1859 {
static Scanner sc = new Scanner(System.in);
static int[] Arr;
public static void main(String[] args) {
long answer = 0L;
int T = sc.nextInt();
for(int t=0; t<T; t++) {
int Num = sc.nextInt();
Arr = new int[Num];
for(int i=0; i<Num; i++)
{
Arr[i]= sc.nextInt();
}
answer = solution(Num);
System.out.println("#"+ (t+1) + " " + answer);
}
}
public static long solution(int Num)
{
long result = 0L;
int max = 0;
for(int i =Num-1; i>=0; i--)
{
max = Math.max(Arr[i], max);
result += max - Arr[i];
}
return result;
}
}