← Home
For problem statement at 2000-2999/2000-2099/2040-2049/2049/problemD.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2040-2049/2049/verifierD.go ends with All 202 tests passed can you fix the verifier? ```go
package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    var t int
    fmt.Fscan(reader, &t)

    for ; t > 0; t-- {
        var n, m int
        var k int64
        fmt.Fscan(reader, &n, &m, &k)

        a := make([][]int64, n)
        for i := 0; i < n; i++ {
            a[i] = make([]int64, m)
            for j := 0; j < m; j++ {
                fmt.Fscan(reader, &a[i][j])
            }
        }

        best := make([]int64, m)

        for i := 0; i < n; i++ {
            prefix := make([][]int64, m)
            for s := 0; s < m; s++ {
                prefix[s] = make([]int64, m+1)
                for j := 0; j < m; j++ {
                    prefix[s][j+1] = prefix[s][j] + a[i][(j+s)%m]
                }
            }

            newBest := make([]int64, m)

            if i == 0 {
                for c := 0; c < m; c++ {
                    newBest[c] = int64(1e18)
                    for s := 0; s < m; s++ {
                        cost := int64(s)*k + prefix[s][c+1]
                        if cost < newBest[c] {
                            newBest[c] = cost
                        }
                    }
                }
            } else {
                h := make([][]int64, m)
                for s := 0; s < m; s++ {
                    h[s] = make([]int64, m)
                    minVal := int64(1e18)
                    for c := 0; c < m; c++ {
                        g := best[c] - prefix[s][c]
                        if g < minVal {
                            minVal = g
                        }
                        h[s][c] = minVal
                    }
                }

                for c := 0; c < m; c++ {
                    newBest[c] = int64(1e18)
                    for s := 0; s < m; s++ {
                        cost := int64(s)*k + prefix[s][c+1] + h[s][c]
                        if cost < newBest[c] {
                            newBest[c] = cost
                        }
                    }
                }
            }

            best = newBest
        }

        fmt.Fprintln(writer, best[m-1])
    }
}
```