• + 1 comment

    I think a little cleaner PHP solution:

    <?php
    
    fscanf(STDIN, '%d %d', $n, $m);
    
    $list = [];
    for ($i = 0; $i < $m; $i++) {
        list($a, $b, $k) = explode(' ', trim(fgets(STDIN)), 3);
    
        $list[$a-1] = ($list[$a-1] ?? 0) + $k;
        $list[$b] = ($list[$b] ?? 0) - $k;
    }
    
    ksort($list);
    
    $running_total = 0;
    $max = 0;
    foreach ($list as $value) {
        $running_total += $value;
        $max = max($max, $running_total);
    }
    
    print $max;