← Home
For problem statement at 2000-2999/2100-2199/2150-2159/2156/problemC.txt this is a correct solution, but verifier at 2000-2999/2100-2199/2150-2159/2156/verifierC.go ends with panic: invalid argument to Intn

goroutine 1 [running]:
math/rand.(*Rand).Intn(0x4000020210?, 0x5?)
	/usr/local/go/src/math/rand/rand.go:180 +0x64
main.generateTests()
	/home/ubuntu/codeforces/2000-2999/2100-2199/2150-2159/2156/verifierC.go:137 +0x264
main.main()
	/home/ubuntu/codeforces/2000-2999/2100-2199/2150-2159/2156/verifierC.go:38 +0x158
exit status 2 can you fix the verifier? package main

import (
	"io"
	"os"
)

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

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

	t := nextInt()
	if t == 0 {
		return
	}

	out := make([]byte, 0, 64*t)

	for i := 0; i < t; i++ {
		n := nextInt()
		k := nextInt()

		freq := make([]int, n+1)
		for j := 0; j < n; j++ {
			freq[nextInt()]++
		}

		suff := make([]int, n+2)
		for j := n; j >= 1; j-- {
			suff[j] = suff[j+1] + freq[j]
		}

		for d := n; d >= 1; d-- {
			goodCount := 0
			if 4*d <= n {
				goodCount += suff[4*d]
			}
			if d <= n {
				goodCount += freq[d]
			}
			if 2*d <= n {
				goodCount += freq[2*d]
			}
			if 3*d <= n {
				goodCount += freq[3*d]
			}

			if goodCount >= n-k {
				out = appendInt(out, d)
				out = append(out, '\n')
				break
			}
		}
	}
	os.Stdout.Write(out)
}

func appendInt(b []byte, v int) []byte {
	if v == 0 {
		return append(b, '0')
	}
	var buf [20]byte
	i := 19
	for v > 0 {
		buf[i] = byte(v%10 + '0')
		v /= 10
		i--
	}
	return append(b, buf[i+1:]...)
}