← Home
For problem statement at 2000-2999/2000-2099/2020-2029/2024/problemB.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2020-2029/2024/verifierB.go ends with All 41 tests passed. can you fix the verifier? package main

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

func readInt(in *bufio.Reader) int64 {
	var n int64
	var c byte
	for {
		c, _ = in.ReadByte()
		if c >= '0' && c <= '9' {
			break
		}
	}
	for {
		n = n*10 + int64(c-'0')
		c, _ = in.ReadByte()
		if c < '0' || c > '9' {
			break
		}
	}
	return n
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

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

		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

		var cans, presses, prev int64
		nActive := int64(n)

		for i := 0; i < n; i++ {
			diff := a[i] - prev
			if nActive*diff < k-cans {
				cans += nActive * diff
				presses += nActive*diff + 1
				nActive--
				prev = a[i]
			} else {
				presses += k - cans
				break
			}
		}
		fmt.Fprintln(out, presses)
	}
}