From 2d6744f3308c97be5551832696c26607e7647858 Mon Sep 17 00:00:00 2001 From: minbr0ther Date: Wed, 9 Mar 2022 09:51:20 +0900 Subject: [PATCH] =?UTF-8?q?10-=EC=97=B0=EC=86=8D=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app.js" | 23 +++++++++++++++++++ .../input.txt" | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 "2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/app.js" create mode 100644 "2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/input.txt" diff --git "a/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/app.js" "b/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/app.js" new file mode 100644 index 0000000..a224040 --- /dev/null +++ "b/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/app.js" @@ -0,0 +1,23 @@ +const fs = require("fs"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().trim().split("\n"); + +let [N, str] = input; +N = +N; +const arr = str.split(" ").map(Number); + +let max = arr[0]; + +for (let i = 1; i < N; i++) { + if (arr[i - 1] > 0 && arr[i - 1] + arr[i] > 0) { + arr[i] += arr[i - 1]; + } + + if (max < arr[i]) { + max = arr[i]; + } +} + +console.log(max); + +// 참고: https://junghyeonsu.tistory.com/210 diff --git "a/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/input.txt" "b/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/input.txt" new file mode 100644 index 0000000..abdd727 --- /dev/null +++ "b/2022/dynamic-programming/10-\354\227\260\354\206\215\355\225\251/input.txt" @@ -0,0 +1,2 @@ +10 +10 -4 3 1 5 6 -35 12 21 -1 \ No newline at end of file