From e9cc33228a87d78831b44c9ebb185d7f784ef873 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Sat, 10 Aug 2024 20:22:34 +0900 Subject: [PATCH] =?UTF-8?q?2024-08-10=20=EC=A3=BC=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + .../11501.js" | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 "oesnuj/\352\267\270\353\246\254\353\224\224/11501.js" diff --git a/oesnuj/README.md b/oesnuj/README.md index 7449522..d0b1139 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -16,4 +16,5 @@ | 12차시 | 2024.07.24 | 재귀 | [하노이 탑](https://www.acmicpc.net/problem/1914) | [#41](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/41) | | 13차시 | 2024.07.28 | DP | [부녀회장이 될테야](https://www.acmicpc.net/problem/2775) | [#44](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/44) | | 14차시 | 2024.08.05 | 해시 | [ 나는야 포켓몬 마스터 이다솜 ](https://www.acmicpc.net/problem/1620) | [#46](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/46) | +| 15차시 | 2024.08.10 | 그리디 | [ 주식 ](https://www.acmicpc.net/problem/11501) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/47) | --- diff --git "a/oesnuj/\352\267\270\353\246\254\353\224\224/11501.js" "b/oesnuj/\352\267\270\353\246\254\353\224\224/11501.js" new file mode 100644 index 0000000..de6d06b --- /dev/null +++ "b/oesnuj/\352\267\270\353\246\254\353\224\224/11501.js" @@ -0,0 +1,21 @@ +const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +const input = require('fs').readFileSync(filepath).toString().trim().split('\n'); + +let answer =""; +for(let i = 2; i < input.length; i += 2) { + answer += calc(i) + "\n"; +} +console.log(answer); + +function calc(i){ + let stockFlow = input[i].split(' ').map(Number); + let profit = 0; + let maxPrice = 0; + for(let j = stockFlow.length - 1; j >= 0; j--) { + if (stockFlow[j] > maxPrice) { + maxPrice = stockFlow[j]; + } + profit += maxPrice - stockFlow[j]; + } + return profit; +} \ No newline at end of file