← Home
For problem statement at 0-999/200-299/260-269/264/problemC.txt this is a correct solution, but verifier at 0-999/200-299/260-269/264/verifierC.go ends with All 100 tests passed can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

const INF int64 = -1000000000000000000

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

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

	n := nextInt()
	if n == 0 {
		return
	}
	q := nextInt()

	values := make([]int64, n)
	for i := 0; i < n; i++ {
		values[i] = int64(nextInt())
	}

	colors := make([]int, n)
	for i := 0; i < n; i++ {
		colors[i] = nextInt()
	}

	dp := make([]int64, n+1)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for qi := 0; qi < q; qi++ {
		a := int64(nextInt())
		b := int64(nextInt())

		for i := 1; i <= n; i++ {
			dp[i] = INF
		}
		dp[0] = 0

		val1 := int64(0)
		col1 := 0
		val2 := INF

		for i := 0; i < n; i++ {
			c := colors[i]
			v := values[i]

			cand := INF
			if dp[c] != INF {
				cand = dp[c] + v*a
			}

			if col1 != c {
				if val1 != INF {
					cand2 := val1 + v*b
					if cand2 > cand {
						cand = cand2
					}
				}
			} else {
				if val2 != INF {
					cand2 := val2 + v*b
					if cand2 > cand {
						cand = cand2
					}
				}
			}

			if cand > dp[c] {
				dp[c] = cand
				if c == col1 {
					val1 = cand
				} else if cand > val1 {
					val2 = val1
					val1 = cand
					col1 = c
				} else if cand > val2 {
					val2 = cand
				}
			}
		}

		fmt.Fprintln(out, val1)
	}
}