๐จ ์ฐธ๊ณ ์ฝ๋
์ฝ๋
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);