← Home
For problem statement at 0-999/500-599/520-529/524/problemC.txt this is a correct solution, but verifier at 0-999/500-599/520-529/524/verifierC.go ends with All tests passed can you fix the verifier? package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	nextInt := func() int {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		return val
	}

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

	a := make([]int, n)
	has := make([]bool, 10000001)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		has[a[i]] = true
	}

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

	for i := 0; i < q; i++ {
		x := nextInt()
		ans := -1

		for S := 1; S <= k; S++ {
			if x%S == 0 {
				b := x / S
				if b <= 10000000 && has[b] {
					ans = S
					break
				}
			}

			found := false
			for c1 := S - 1; c1 >= (S+1)/2; c1-- {
				c2 := S - c1
				for _, val := range a {
					rem := x - c1*val
					if rem > 0 && rem%c2 == 0 {
						b := rem / c2
						if b <= 10000000 && has[b] {
							ans = S
							found = true
							break
						}
					}
				}
				if found {
					break
				}
			}
			if found || ans != -1 {
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}