For problem statement at 1000-1999/1000-1099/1090-1099/1092/problemD2.txt this is a correct solution, but verifier at 1000-1999/1000-1099/1090-1099/1092/verifierD2.go ends with All 100 tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
var n int
if _, err := fmt.Fscan(reader, &n); err != nil {
return
}
a := make([]int, n)
maxVal := 0
for i := 0; i < n; i++ {
fmt.Fscan(reader, &a[i])
if a[i] > maxVal {
maxVal = a[i]
}
}
stack := make([]int, 0, n)
for i := 0; i < n; i++ {
x := a[i]
if len(stack) == 0 {
stack = append(stack, x)
} else if stack[len(stack)-1] == x {
stack = stack[:len(stack)-1]
} else if stack[len(stack)-1] > x {
stack = append(stack, x)
} else {
fmt.Println("NO")
return
}
}
if len(stack) > 1 {
fmt.Println("NO")
} else if len(stack) == 1 && stack[0] != maxVal {
fmt.Println("NO")
} else {
fmt.Println("YES")
}
}