Skip to content

Commit

Permalink
2024-08-10 ์ฃผ์‹
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj committed Aug 10, 2024
1 parent 060f3d8 commit e9cc332
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
21 changes: 21 additions & 0 deletions oesnuj/๊ทธ๋ฆฌ๋””/11501.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit e9cc332

Please sign in to comment.