✨ 문제 ✨

✨ 정답 ✨
const { count } = require("console");
const fs = require("fs");
const { nextTick } = require("process");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./예제.txt";
let input = fs.readFileSync(filePath).toString().trim();
input=input.split('\n');
let N=+input.shift();
let array=input.shift().split(' ').map((el)=>+el);
let dp=new Array(N).fill(0)
let dpArray=[];
for (let i=0;i<N;i++){
let max=0;
let maxIndex=-1;
for (let j=0;j<i;j++){
if (array[i]>array[j]&&dp[j]>max){
max=dp[j];
maxIndex=j;
}
}
dp[i]=max+1;
if (maxIndex===-1){
dpArray[i]=[array[i]]
}else{
dpArray[i]=[...dpArray[maxIndex], array[i]]
}
}
console.log(Math.max(...dp))
console.log(dpArray[dp.indexOf(Math.max(...dp))].join(' '))
🧵 참고한 정답지 🧵
💡💡 기억해야 할 점 💡💡