← Home
For problem statement at 0-999/0-99/80-89/83/problemB.txt this is a correct solution, but verifier at 0-999/0-99/80-89/83/verifierB.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	// Use buffered I/O for fast execution
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	// Helper to parse int64
	readInt64 := func() int64 {
		scanner.Scan()
		val, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		return val
	}

	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())

	if !scanner.Scan() {
		return
	}
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)

	a := make([]int64, n)
	var sum int64
	for i := 0; i < n; i++ {
		val := readInt64()
		a[i] = val
		sum += val
	}

	// If total needed visits are less than k, we can't perform k examinations
	// The problem says "less than k", but implies if queue empties exactly at k, it's fine (empty output).
	// If sum < k, then we finish early -> -1.
	// If sum == k, we finish exactly at k -> empty output (handled by logic below).
	if sum < k {
		fmt.Fprint(out, "-1")
		return
	}

	// Binary search for x: the number of full rounds of examinations we can perform.
	// Cost function C(val) = sum(min(a[i], val)). We want max x such that C(x) <= k.
	// Max possible answer is max(a_i) <= 10^9.
	var low, high int64 = 0, 2000000000
	var x int64 = 0

	for low <= high {
		mid := (low + high) / 2
		var currentCost int64
		for _, v := range a {
			if v < mid {
				currentCost += v
			} else {
				currentCost += mid
			}
		}

		if currentCost <= k {
			x = mid
			low = mid + 1
		} else {
			high = mid - 1
		}
	}

	// Calculate remainder of examinations after x full rounds
	var used int64
	for _, v := range a {
		if v < x {
			used += v
		} else {
			used += x
		}
	}
	remainder := k - used

	// Identify animals that still need visits after x rounds
	// Animal i remains if a[i] > x
	type Animal struct {
		id  int
		val int64
	}
	var candidates []Animal
	// Preallocate for efficiency
	candidates = make([]Animal, 0, n)

	for i, v := range a {
		if v > x {
			candidates = append(candidates, Animal{id: i + 1, val: v})
		}
	}

	// We have 'remainder' exams left to distribute among 'candidates'.
	// The candidates are in the correct cyclic order relative to each other.
	// We process the first 'remainder' candidates one more time.
	// Those among them who still need visits (val > x + 1) move to the back.
	// The rest (from index 'remainder' to end) haven't been processed in this partial round, so they stay at the front.

	first := true

	// Print Part 2: Animals not reached in the partial round
	for i := int64(0); i < int64(len(candidates)); i++ {
		if i >= remainder {
			if !first {
				fmt.Fprint(out, " ")
			}
			fmt.Fprint(out, candidates[i].id)
			first = false
		}
	}

	// Print Part 1: Animals processed in partial round that still remain
	for i := int64(0); i < remainder; i++ {
		if candidates[i].val > x+1 {
			if !first {
				fmt.Fprint(out, " ")
			}
			fmt.Fprint(out, candidates[i].id)
			first = false
		}
	}
	fmt.Fprintln(out)
}
```