• + 0 comments

    Superb...... Same I implemented in JS

    function processData(input) {
        let arr = input.split('\n');
        const NM = arr[0].split(' ').map(Number);
        const N = NM[0];
        const M = NM[1];
        let obj = {};
        for (let i = 1; i <= M; i++) {
            const abk = arr[i].split(' ').map(Number);
            const a = abk[0]; const b = abk[1]; const k = abk[2];
            obj[a] = obj[a] ? obj[a] + k : k;
            obj[b+1] = obj[b+1] ? obj[b+1] - k : (k*-1);
        }
        delete(obj[N+1]);
        let MAX = 0; let X = 0;
        for (const key in obj) {
            X += obj[key];
            if (MAX < X) MAX = X;
        }
        console.log(MAX);
    }