diff --git a/su-lim/week1/1-11054.js b/su-lim/week1/1-11054.js new file mode 100644 index 0000000..46339e1 --- /dev/null +++ b/su-lim/week1/1-11054.js @@ -0,0 +1,35 @@ +// 백준 - 가장 긴 바이토닉 부분 수열 + +const fs = require("fs"); +const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); +const n =+input[0]; +const numberList = input[1].split(" ").map((e) => +e); + +function main(N, numberList) { + let answer = 0; + + const reverseNumberList = numberList.slice().reverse(); + + // k일 때, 증가 배열의 최대 수 / 감소 배열의 최대 수 저장 + let increase = new Array(N).fill(1); + let decrease = new Array(N).fill(1); + + for (let i = 0; i < N; i++) { + for (let j = 0; j < i; j++) { + if (numberList[i] > numberList[j]) { + increase[i] = Math.max(increase[i], increase[j] + 1); + } + if (reverseNumberList[i] > reverseNumberList[j]) { + decrease[i] = Math.max(decrease[i], decrease[j] + 1); + } + } + } + + for (let i = 0; i < N; i++) { + answer = Math.max(increase[i] + decrease[N - i - 1] - 1, answer); + } + return answer; +} + +const answer = main(n, numberList); +console.log(answer); diff --git a/su-lim/week1/2-1931.js b/su-lim/week1/2-1931.js new file mode 100644 index 0000000..354428b --- /dev/null +++ b/su-lim/week1/2-1931.js @@ -0,0 +1,32 @@ +// 백준 - 회의실 배정 + +const fs = require("fs"); +const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); +const N = +input[0]; +let timeList = []; + +for(let i=1;i +e)); +} + +function main(N, timeList) { + let count = 0; + let startTime = 0; + + timeList.sort(function(a,b){ + return a[0] - b[0]; + }) + timeList.sort(function(a,b){ + return a[1] - b[1]; + }) + + for(let i=0;i= startTime){ + count += 1; + startTime = timeList[i][1]; + } + } + return count; +} + +console.log(main(N, timeList)); diff --git a/su-lim/week1/4-1806.js b/su-lim/week1/4-1806.js new file mode 100644 index 0000000..3bdfc72 --- /dev/null +++ b/su-lim/week1/4-1806.js @@ -0,0 +1,34 @@ +// 백준 - 부분합 + +const fs = require("fs"); +const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); +const [N, S] = input[0].split(" ").map((e)=> +e); +const sequence = input[1].split(" ").map((e) => +e); + +let [L, R] = [0, 0]; +let MAX_SIZE = 100000; +let size = MAX_SIZE; +let sum = 0; + +while( R !== N ){ + + // L부터 R까지 합 구하기 + sum = 0; + for(let i=L; i= S){ + size = R-L+1; + if(size === 1) break; + L += 1; + } + else{ + R += 1; + if(size <= R-L+1){ + L += 1; + } + } + +} +console.log(size === MAX_SIZE ? 0 : size);