For problem statement at 1000-1999/1700-1799/1790-1799/1791/problemG1.txt this is a correct solution, but verifier at 1000-1999/1700-1799/1790-1799/1791/verifierG1.go ends with All tests passed can you fix the verifier? package main
import (
"os"
"sort"
)
func main() {
buf := make([]byte, 8192)
var pos, length int
readByte := func() byte {
if pos >= length {
pos = 0
var err error
length, err = os.Stdin.Read(buf)
if err != nil || length == 0 {
return 0
}
}
res := buf[pos]
pos++
return res
}
readInt := func() int {
var res int
b := readByte()
for b <= 32 {
if b == 0 {
return 0
}
b = readByte()
}
for b > 32 {
res = res*10 + int(b-'0')
b = readByte()
}
return res
}
readInt64 := func() int64 {
var res int64
b := readByte()
for b <= 32 {
if b == 0 {
return 0
}
b = readByte()
}
for b > 32 {
res = res*10 + int64(b-'0')
b = readByte()
}
return res
}
t := readInt()
if t == 0 {
return
}
out := make([]byte, 0, 1<<16)
writeInt := func(v int) {
if v == 0 {
out = append(out, '0')
} else {
var tmp [20]byte
idx := 20
for v > 0 {
idx--
tmp[idx] = byte(v%10 + '0')
v /= 10
}
out = append(out, tmp[idx:]...)
}
out = append(out, '\n')
if len(out) > 1<<15 {
os.Stdout.Write(out)
out = out[:0]
}
}
for tc := 0; tc < t; tc++ {
n := readInt()
c := readInt64()
costs := make([]int, n)
for i := 0; i < n; i++ {
costs[i] = readInt() + i + 1
}
sort.Ints(costs)
ans := 0
var sum int64 = 0
for i := 0; i < n; i++ {
if sum+int64(costs[i]) <= c {
sum += int64(costs[i])
ans++
} else {
break
}
}
writeInt(ans)
}
if len(out) > 0 {
os.Stdout.Write(out)
}
}