← Home
For problem statement at 2000-2999/2000-2099/2060-2069/2069/problemE.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2060-2069/2069/verifierE.go ends with All 114 tests passed. can you fix the verifier? package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

	var t int
	if _, err := fmt.Fscan(reader, &t); err != nil {
		return
	}

	for tc := 0; tc < t; tc++ {
		var s string
		fmt.Fscan(reader, &s)

		var a, b, ab, ba int
		fmt.Fscan(reader, &a, &b, &ab, &ba)

		countA := 0
		countB := 0
		for i := 0; i < len(s); i++ {
			if s[i] == 'A' {
				countA++
			} else {
				countB++
			}
		}

		req := max(0, max(countA-a, countB-b))

		var poolAB []int
		var poolBA []int
		F := 0

		n := len(s)
		i := 0
		for i < n {
			j := i + 1
			for j < n && s[j] != s[j-1] {
				j++
			}
			L := j - i
			if L > 1 {
				if L%2 != 0 {
					F += L / 2
				} else {
					if s[i] == 'A' {
						poolAB = append(poolAB, L/2)
					} else {
						poolBA = append(poolBA, L/2)
					}
				}
			}
			i = j
		}

		sumAB := 0
		for _, k := range poolAB {
			sumAB += k
		}
		sumBA := 0
		for _, k := range poolBA {
			sumBA += k
		}

		SMax := sumAB + sumBA + F

		if SMax < req {
			fmt.Fprintln(writer, "NO")
			continue
		}

		costX := 0
		if sumAB > ab {
			diff := sumAB - ab
			sort.Slice(poolAB, func(i, j int) bool {
				return poolAB[i] > poolAB[j]
			})
			cur := 0
			for _, k := range poolAB {
				cur += k
				costX++
				if cur >= diff {
					break
				}
			}
		}

		costY := 0
		if sumBA > ba {
			diff := sumBA - ba
			sort.Slice(poolBA, func(i, j int) bool {
				return poolBA[i] > poolBA[j]
			})
			cur := 0
			for _, k := range poolBA {
				cur += k
				costY++
				if cur >= diff {
					break
				}
			}
		}

		maxTotal := SMax - costX - costY
		maxTotal = min(maxTotal, ab+ba)

		if maxTotal >= req {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}