← Home
For problem statement at 0-999/300-399/340-349/349/problemB.txt this is a correct solution, but verifier at 0-999/300-399/340-349/349/verifierB.go ends with All 10 tests passed can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)

	var v int
	fmt.Fscan(in, &v)

	cost := make([]int, 10)
	minCost := int(1e9)
	for i := 1; i <= 9; i++ {
		fmt.Fscan(in, &cost[i])
		if cost[i] < minCost {
			minCost = cost[i]
		}
	}

	length := v / minCost
	if length == 0 {
		fmt.Print(-1)
		return
	}

	var b strings.Builder
	b.Grow(length)

	rem := v
	for pos := 0; pos < length; pos++ {
		for d := 9; d >= 1; d-- {
			if rem-cost[d] >= (length-pos-1)*minCost {
				b.WriteByte(byte('0' + d))
				rem -= cost[d]
				break
			}
		}
	}

	fmt.Print(b.String())
}