• + 1 comment

    New on this site and having hard time with this task. Luckily found your comment and found my mistake. here's my short version of yours

    <?php
    $_fp = fopen("php://stdin", "r");
    $_fp2 = fopen('php://stdout', 'w');
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    
    fscanf($_fp, "%d %d", $n, $m);
    
    $r = [];
    
    for($i=0; $i<$m; $i++){
        fscanf($_fp, '%d %d %d', $a, $b, $k);
    
        $r[$a] += $k;
        $r[$b+1] -= $k;   
    }
    ksort($r);
    
    $max = $sum = 0;
    
    foreach ($r as $val) {
        $sum += $val;
        if ($sum > $max) {
            $max = $sum;
        }
    }
    
    fwrite($_fp2, $max);  
    ?>