From 11cf8814a97918f1424bfce9a6f8d1786100f156 Mon Sep 17 00:00:00 2001 From: ramrami-B <21801034@handong.ac.kr> Date: Wed, 17 Jan 2024 00:22:57 +0900 Subject: [PATCH] =?UTF-8?q?Create=201859=EB=B0=B1=EB=A7=8C=EC=9E=A5?= =?UTF-8?q?=EC=9E=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\247\214\354\236\245\354\236\220.java" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "\353\260\261\355\225\230\353\236\214/1859\353\260\261\353\247\214\354\236\245\354\236\220.java" diff --git "a/\353\260\261\355\225\230\353\236\214/1859\353\260\261\353\247\214\354\236\245\354\236\220.java" "b/\353\260\261\355\225\230\353\236\214/1859\353\260\261\353\247\214\354\236\245\354\236\220.java" new file mode 100644 index 00000000..baddc1bd --- /dev/null +++ "b/\353\260\261\355\225\230\353\236\214/1859\353\260\261\353\247\214\354\236\245\354\236\220.java" @@ -0,0 +1,34 @@ +import java.util.*; + +public class Solution { + public static void main(String args[]) throws Exception { + Scanner sc = new Scanner(System.in); + + int T = sc.nextInt(); + + for(int t=1; t < T+1; t++) { + long answer = 0; + + int N = sc.nextInt(); + int[] salePrices = new int[N]; + + for(int i = 0; i < N; i++) { + salePrices[i] = sc.nextInt(); + } + + int i = N-1; + int j = i-1; + + while(i > -1 && j > -1) { + if(salePrices[i] > salePrices[j]) { + answer += salePrices[i] - salePrices[j]; + } else { + i = j; + } + j--; + } + + System.out.println("#" + t + " " + answer); + } + } +} \ No newline at end of file