Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions su-lim/week1/1-11054.js
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main으로 구분지어 주는 것도 좋아보이네요. 대부분의 코테 플랫폼도 solution 형태로 코드를 작성하도록 되어있다보니 연습도 할 겸 좋은 것 같아요!

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);
32 changes: 32 additions & 0 deletions su-lim/week1/2-1931.js
Original file line number Diff line number Diff line change
@@ -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<N+1;i++){
timeList.push(input[i].split(" ").map((e) => +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];
})
Comment on lines +16 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare function을 하나로 적으면 더 간단해질 것 같아요. (대충 로직은 알고 있을 거라고 생각하니까 arrow function 형태로 적었습니다.)

const compareFunction = (a, b) => (a[0] - b[0] !== 0 ? a[0] - b[0] : a[1] - b[1])


for(let i=0;i<timeList.length;i++){
if(timeList[i][0] >= startTime){
count += 1;
startTime = timeList[i][1];
}
}
return count;
}

console.log(main(N, timeList));
34 changes: 34 additions & 0 deletions su-lim/week1/4-1806.js
Original file line number Diff line number Diff line change
@@ -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<R+1; i++){
sum += sequence[i];
}

if(sum >= 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);