For problem statement at 0-999/0-99/10-19/10/problemD.txt this is a correct solution, but verifier at 0-999/0-99/10-19/10/verifierD.go ends with All tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
if !scanner.Scan() {
return
}
n, _ := strconv.Atoi(scanner.Text())
a := make([]int, n+1)
for i := 1; i <= n; i++ {
scanner.Scan()
a[i], _ = strconv.Atoi(scanner.Text())
}
if !scanner.Scan() {
return
}
m, _ := strconv.Atoi(scanner.Text())
b := make([]int, m+1)
for i := 1; i <= m; i++ {
scanner.Scan()
b[i], _ = strconv.Atoi(scanner.Text())
}
dp := make([]int, m+1)
prev := make([]int, m+1)
for i := 1; i <= n; i++ {
cur := 0
last := 0
for j := 1; j <= m; j++ {
if a[i] == b[j] {
if cur+1 > dp[j] {
dp[j] = cur + 1
prev[j] = last
}
} else if a[i] > b[j] {
if dp[j] > cur {
cur = dp[j]
last = j
}
}
}
}
bestLen := 0
bestEnd := 0
for j := 1; j <= m; j++ {
if dp[j] > bestLen {
bestLen = dp[j]
bestEnd = j
}
}
fmt.Println(bestLen)
if bestLen > 0 {
path := make([]int, 0, bestLen)
curr := bestEnd
for curr > 0 {
path = append(path, b[curr])
curr = prev[curr]
}
for i := len(path) - 1; i >= 0; i-- {
if i < len(path)-1 {
fmt.Print(" ")
}
fmt.Print(path[i])
}
fmt.Println()
}
}