← Home
For problem statement at 1000-1999/1600-1699/1680-1689/1685/problemB.txt this is a correct solution, but verifier at 1000-1999/1600-1699/1680-1689/1685/verifierB.go ends with case 10 failed
input:
1
0 0 2 2
ABBAABAB
expected:YES
actual:NO
exit status 1 can you fix the verifier? ```go
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := nextInt(scanner)
	for _ = range make([]int, t) {
		_ = nextInt(scanner)
		_ = nextInt(scanner)
		c := nextInt(scanner)
		d := nextInt(scanner)
		s := nextString(scanner)

		n := len(s)

		// Compute p and q
		p, q := 0, 0
		var runs [][]int // 0: char 'A'=0 'B'=1, 1: len
		i := 0
		for i < n {
			ch := int(s[i] - 'A') // 0 A, 1 B
			len := 0
			for i < n && int(s[i]-'A') == ch {
				len++
				i++
			}
			runs = append(runs, []int{ch, len})
		}
		m := len(runs)
		for i := 0; i < m-1; i++ {
			if runs[i][0] == 0 {
				p++
			} else {
				q++
			}
		}

		if c > p {
			fmt.Println("NO")
			continue
		}

		// Build components
		var typeA, typeB, typeC []int
		cur := 0
		for cur < m-1 {
			start := cur
			for cur < m-2 && runs[cur+1][1] == 1 {
				cur++
			}
			end := cur
			lenComp := end - start + 1
			if lenComp < 1 {
				cur++
				continue
			}
			firstCh := runs[start][0]
			startsWithAB := firstCh == 0
			endsWithAB := (lenComp%2 == 1) == startsWithAB
			hasLeftOpen := startsWithAB
			hasRightOpen := endsWithAB
			numAB := 0
			if startsWithAB {
				numAB = (lenComp + 1) / 2
			} else {
				numAB = lenComp / 2
			}
			if numAB > 0 {
				if hasLeftOpen && hasRightOpen {
					typeB = append(typeB, numAB)
				} else if hasLeftOpen || hasRightOpen {
					typeA = append(typeA, numAB)
				} else {
					typeC = append(typeC, numAB)
				}
			}
			cur++
		}

		// Compute total_good
		totalGood := 0
		for _, al := range typeA {
			totalGood += al
		}
		for _, al := range typeB {
			totalGood += al
		}

		// Compute sum_C
		sumC := 0
		for _, al := range typeC {
			sumC += al
		}

		// num_free is included in typeB as alpha=1

		cc := c // since free included

		minCovered := 0
		if totalGood >= cc {
			// compute max_m
			bAlphas := make([]int, len(typeB))
			copy(bAlphas, typeB)
			sort.Ints(bAlphas)
			kB := len(bAlphas)
			pSum := 0
			maxM := 0
			for mm := 1; mm <= kB; mm++ {
				pSum += bAlphas[mm-1]
				if pSum <= cc {
					maxM = mm
				} else {
					break
				}
			}
			minCovered = cc - maxM
		} else {
			k := len(typeB)
			coveredGood := totalGood - k
			rr := cc - totalGood
			if sumC < rr {
				fmt.Println("NO")
				continue
			}
			// compute min_number for typeC
			cAlphas := make([]int, len(typeC))
			copy(cAlphas, typeC)
			sort.Sort(sort.Reverse(sort.IntSlice(cAlphas)))
			curSum := 0
			count := 0
			for _, al := range cAlphas {
				curSum += al
				count++
				if curSum >= rr {
					break
				}
			}
			coveredC := rr + count
			minCovered = coveredGood + coveredC
		}

		if minCovered <= q-d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	x, _ := strconv.Atoi(s.Text())
	return x
}

func nextString(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}
```