https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5LrsUaDxcDFAXc
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
static Scanner sc = new Scanner(System.in);
public static void main(String args[]) throws Exception
{
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
int a[] = new int[N];
for(int i=0; i<N; i++) a[i] = sc.nextInt();
long sum = 0;
int max = a[N-1];
for(int i=N-2; i>=0; i--) {
if( a[i] > max ) max = a[i];
else sum += max - a[i];
}
System.out.format( "#%d %d\n", test_case, sum );
}
}
}
'알고리즘 > 삼성 SW expert Academy' 카테고리의 다른 글
[SWEA] 2001. 파리 퇴치_JAVA (0) | 2022.05.06 |
---|---|
[SWEA] 2005. 파스칼의 삼각형_JAVA (0) | 2022.05.06 |
[SWEA] 2027. 대각선 출력하기_JAVA (0) | 2022.05.04 |
[SWEA] 2063. 중간값 찾기_JAVA (0) | 2022.05.04 |
[SWEA] 2058. 자릿수 더하기_JAVA (0) | 2022.05.04 |