[백준/Node.js] 퇴사 #14501

welchs·2021년 8월 1일
0

백준

목록 보기
5/10
var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().split('\n');

const solution = (N, counseling) => {
  const dp = new Array(N).fill(0);

  for (let i = 0; i < N; i++) {
    const [cost, profit] = counseling[i];
    if (i + cost > N) continue;
    dp[i] = dp[i] + profit;
    for (let j = i + cost; j < N; j++) {
      dp[j] = Math.max(dp[j], dp[i]);
    }
  }
  return Math.max(...dp);
};

const N = Number(input[0]);
const counseling = input
  .slice(1)
  .map((v) => v.split(' ').map((v) => Number(v)));
console.log(solution(N, counseling));
profile
고수가 되고 싶은 조빱

0개의 댓글