• + 2 comments
    process.stdin.resume();
    process.stdin.setEncoding('ascii');
    
    var input_stdin = "";
    var input_stdin_array = "";
    var input_currentline = 0;
    
    process.stdin.on('data', function (data) {
        input_stdin += data;
    });
    
    process.stdin.on('end', function () {
        input_stdin_array = input_stdin.split("\n");
        main();
    });
    
    function readLine() {
        return input_stdin_array[input_currentline++];
    }
    
    /////////////// ignore above this line ////////////////////
    
    function main() {
        var n_temp = readLine().split(' ');
        var listSize = parseInt(n_temp[0]);
        var lineNumber = parseInt(n_temp[1]);
        let slopList = new Array();
        for(let i = 0;i < listSize;i++){
            slopList.push(0);
        }
    
        for(var a0 = 0; a0 < lineNumber; a0++){
            var a_temp = readLine().split(' ');
    
            const beginElementPos = parseInt(a_temp[0]);
            const endElementPos = parseInt(a_temp[1]);
            const addValue = parseInt(a_temp[2]);
            slopList[beginElementPos-1] += addValue;
            if (endElementPos<listSize){
              slopList[endElementPos]-=addValue;
            }
        }
        let actualList = new Array();
        let sum = 0;
        for (let i=0; i<listSize; i++) {
            sum += slopList[i];
            actualList.push(sum);
        }
    
       let max =  actualList.reduce((acc,val)=>{
    
            return (acc>val)?acc:val;
        },0);
        console.log(max);
    
    }