Notice
Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 1912๋ฒˆ] ์—ฐ์†ํ•ฉ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 1912๋ฒˆ] ์—ฐ์†ํ•ฉ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 6. 6. 17:56
728x90
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/1912

 

1912๋ฒˆ: ์—ฐ์†ํ•ฉ

์ฒซ์งธ ์ค„์— ์ •์ˆ˜ n(1 ≤ n ≤ 100,000)์ด ์ฃผ์–ด์ง€๊ณ  ๋‘˜์งธ ์ค„์—๋Š” n๊ฐœ์˜ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆ˜์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ˆ˜๋Š” -1,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค.

www.acmicpc.net

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
  input.push(line);
  if (input.length === 2) {
    rl.close();
  }
}).on('close', function () {
  input.shift();
  const numArr = input[0].split(' ').map(Number);

  const DP = [];

  for (let i = 0; i < numArr.length; i++) {
    DP[i] = numArr[i];
    if (DP[i] < DP[i - 1] + numArr[i]) {
      DP[i] = DP[i - 1] + numArr[i];
    }
  }

  console.log(Math.max(...DP));
});
728x90
๋ฐ˜์‘ํ˜•
Comments