For problem statement at 0-999/700-799/790-799/799/problemC.txt this is a correct solution, but verifier at 0-999/700-799/790-799/799/verifierC.go ends with All tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
"sort"
)
type Fountain struct {
beauty int
cost int
}
func main() {
reader := bufio.NewReader(os.Stdin)
var n, c, d int
fmt.Fscan(reader, &n, &c, &d)
var C []Fountain
var D []Fountain
for i := 0; i < n; i++ {
var b, p int
var typ string
fmt.Fscan(reader, &b, &p, &typ)
if typ == "C" {
if p <= c {
C = append(C, Fountain{b, p})
}
} else {
if p <= d {
D = append(D, Fountain{b, p})
}
}
}
ans := 0
ans = max(ans, solve(C, c))
ans = max(ans, solve(D, d))
maxC := 0
for _, f := range C {
if f.beauty > maxC {
maxC = f.beauty
}
}
maxD := 0
for _, f := range D {
if f.beauty > maxD {
maxD = f.beauty
}
}
if maxC > 0 && maxD > 0 {
ans = max(ans, maxC+maxD)
}
fmt.Println(ans)
}
func solve(f []Fountain, maxCost int) int {
if len(f) < 2 {
return 0
}
sort.Slice(f, func(i, j int) bool {
return f[i].cost < f[j].cost
})
pref := make([]int, len(f))
pref[0] = f[0].beauty
for i := 1; i < len(f); i++ {
pref[i] = max(pref[i-1], f[i].beauty)
}
res := 0
for i := 1; i < len(f); i++ {
rem := maxCost - f[i].cost
idx := sort.Search(len(f), func(k int) bool {
return f[k].cost > rem
}) - 1
j := i - 1
if idx < j {
j = idx
}
if j >= 0 {
res = max(res, f[i].beauty+pref[j])
}
}
return res
}
func max(a, b int) int {
if a > b {
return a
}
return b
}