← Home
For problem statement at 0-999/300-399/310-319/314/problemA.txt this is a correct solution, but verifier at 0-999/300-399/310-319/314/verifierA.go ends with All 157 tests passed. can you fix the verifier? package main

import (
	"bufio"
	"bytes"
	"io"
	"math/bits"
	"os"
	"strconv"
)

type FastScanner struct {
	data []byte
	idx  int
}

func (fs *FastScanner) nextInt64() int64 {
	n := len(fs.data)
	for fs.idx < n {
		c := fs.data[fs.idx]
		if c != ' ' && c != '\n' && c != '\r' && c != '\t' {
			break
		}
		fs.idx++
	}
	sign := int64(1)
	if fs.data[fs.idx] == '-' {
		sign = -1
		fs.idx++
	}
	var v int64
	for fs.idx < n {
		c := fs.data[fs.idx]
		if c < '0' || c > '9' {
			break
		}
		v = v*10 + int64(c-'0')
		fs.idx++
	}
	return sign * v
}

type U128 struct {
	hi uint64
	lo uint64
}

func add64(x U128, y uint64) U128 {
	lo, c := bits.Add64(x.lo, y, 0)
	hi, _ := bits.Add64(x.hi, 0, c)
	return U128{hi: hi, lo: lo}
}

func cmp(a, b U128) int {
	if a.hi < b.hi {
		return -1
	}
	if a.hi > b.hi {
		return 1
	}
	if a.lo < b.lo {
		return -1
	}
	if a.lo > b.lo {
		return 1
	}
	return 0
}

func main() {
	data, _ := io.ReadAll(os.Stdin)
	fs := FastScanner{data: data}

	n := int(fs.nextInt64())
	k := fs.nextInt64()
	c := uint64(-k)

	var w U128
	survivors := 0

	var out bytes.Buffer
	first := true

	for i := 1; i <= n; i++ {
		a := uint64(fs.nextInt64())
		prod := uint64(survivors) * uint64(n-i)
		hi, lo := bits.Mul64(prod, a)
		t := U128{hi: hi, lo: lo}

		if cmp(t, add64(w, c)) == 1 {
			if !first {
				out.WriteByte(' ')
			}
			first = false
			out.WriteString(strconv.Itoa(i))
		} else {
			w = add64(w, a*uint64(survivors))
			survivors++
		}
	}

	bw := bufio.NewWriter(os.Stdout)
	bw.Write(out.Bytes())
	bw.WriteByte('\n')
	bw.Flush()
}