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