← Home
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 (
	"fmt"
	"io"
	"os"
)

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	var n, maxVal int

	idx := 0

	readInt := func() int {
		for idx < len(buf) && buf[idx] < '0' {
			idx++
		}
		if idx >= len(buf) {
			return 0
		}
		res := 0
		for idx < len(buf) && buf[idx] >= '0' && buf[idx] <= '9' {
			res = res*10 + int(buf[idx]-'0')
			idx++
		}
		return res
	}

	n = readInt()
	if n == 0 {
		return
	}

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		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[len(stack)-1] < x {
			fmt.Println("NO")
			return
		}

		if len(stack) > 0 && stack[len(stack)-1] == x {
			stack = stack[:len(stack)-1]
		} else {
			stack = append(stack, x)
		}
	}

	if len(stack) == 0 || (len(stack) == 1 && stack[0] == maxVal) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}