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

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	var pos int
	readInt := 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
	}

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		k := readInt()
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = readInt()
		}

		seen := make([]int, n+2)
		marker := 0

		check := func(x int) bool {
			if x == 0 {
				return true
			}
			count := 0
			found := 0
			marker++
			for j := 0; j < n; j++ {
				v := a[j]
				if v < x {
					if seen[v] != marker {
						seen[v] = marker
						found++
						if found == x {
							count++
							if count == k {
								return true
							}
							found = 0
							marker++
						}
					}
				}
			}
			return false
		}

		low, high := 0, n/k
		ans := 0
		for low <= high {
			mid := low + (high-low)/2
			if check(mid) {
				ans = mid
				low = mid + 1
			} else {
				high = mid - 1
			}
		}
		out.WriteString(strconv.Itoa(ans) + "\n")
	}
}