Skip to content

Commit

Permalink
10-연속합
Browse files Browse the repository at this point in the history
  • Loading branch information
minbr0ther committed Mar 9, 2022
1 parent 06edee8 commit 2d6744f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 2022/dynamic-programming/10-연속합/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
2 changes: 2 additions & 0 deletions 2022/dynamic-programming/10-연속합/input.txt
@@ -0,0 +1,2 @@
10
10 -4 3 1 5 6 -35 12 21 -1

0 comments on commit 2d6744f

Please sign in to comment.