๐ŸŽฒ ๋ฐฑ์ค€ 8980๋ฒˆ ํƒ๋ฐฐ

Jeongeunยท2023๋…„ 11์›” 10์ผ
0

๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
132/186

๋ฐฑ์ค€ 8980๋ฒˆ

๐ŸŽจ ์ฐธ๊ณ ์ฝ”๋“œ

์ฝ”๋“œ

const fs = require('fs'); 
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const [N, C] = input.shift().split(" ").map(Number);
const infoNum = +input.shift();
input = input
  .map((el) => el.split(" ").map(Number))
  .sort((a, b) => a[1] - b[1]);

const result = new Array(N + 1).fill(0);
let answer = 0;
for (let i = 0; i < infoNum; i++) {
  const [start, end, box] = input[i];
  const temp = result.slice(start, end);
  const max = Math.max(...temp);
  const possibleBox = Math.min(C - max, box);
  for (let j = start; j < end; j++) {
    result[j] += possibleBox;
  }
  answer += possibleBox;
}
console.log(answer);

0๊ฐœ์˜ ๋Œ“๊ธ€