티스토리 뷰
https://www.acmicpc.net/problem/13398
13398번: 연속합 2
첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다.
www.acmicpc.net
const fs = require('fs');
const [n, ...num] = fs.readFileSync("./dev/stdin").toString().trim().split('\n');
const N = +n;
const nums1 = num[0].split(' ').map(Number);
const nums2 = num[0].split(' ').map(Number).reverse();
const dp1 = new Array(N).fill(0);
const dp2 = new Array(N).fill(0);
dp1[0] = nums1[0]
let max = nums1[0]
for(let i = 1; i<N; i++){
dp1[i] = Math.max(dp1[i-1]+nums1[i],nums1[i]);
max = Math.max(max,dp1[i]);
}
dp2[0] = nums2[0];
for(let i =1 ; i<N; i++){
dp2[i] = Math.max(dp2[i-1]+nums2[i], nums2[i])
}
for(let i = 1; i<N-1; i++){
const temp = dp1[i-1]+dp2[N-2-i]
max = Math.max(temp,max)
}
console.log(max)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 16947번: 서울 지하철 2호선 (0) | 2022.07.01 |
---|---|
Node.js) 백준 16929번: Two Dots (0) | 2022.06.30 |
Node.js)백준 16235번: 나무 재테크 (0) | 2022.06.26 |
Node.js) 백준 15988번: 1, 2, 3 더하기 3 (0) | 2022.06.24 |
Node.js) 백준 2294번: 동전2 (0) | 2022.06.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 그래프
- 동적프로그래밍
- 투포인터 연습
- 서버개발
- 개발자면접
- 은둔청년체험
- 다이나믹프로그래밍
- 면접비
- MySQL
- MOD
- create databases;
- create db
- 면접질문
- node.js
- 최소공통조상
- 롱베케이션
- 투포인터
- BFS
- DB 생성
- 다이나밍프로그래밍
- 서버점검
- 로드나인
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함