• + 1 comment

    Here is in Go:

    package main
    
    import (
        "fmt"
        "os"
        "bufio"
    )
    
    const MinInt = -(int(^uint(0) >> 1)  - 1) 
    
    func main() {
        var n, m, a, b, k int
      
        io := bufio.NewReader(os.Stdin)
        fmt.Fscan(io, &n)
        fmt.Fscan(io, &m)
        l := make([]int, n)
        
        for i := 1; i <= m; i++ {
            fmt.Fscan(io, &a)
            fmt.Fscan(io, &b)
            fmt.Fscan(io, &k)
            
            l[a-1] += k
            if b <= n -1 {
                l[b] -= k
            }
        }
        
        max := MinInt
        sum := 0
        for _,v := range l {
            sum += v
            if sum >= max {
                max = sum
            }
        }
        fmt.Print(max)  
    }