For problem statement at 1000-1999/1300-1399/1370-1379/1370/problemD.txt this is a correct solution, but verifier at 1000-1999/1300-1399/1370-1379/1370/verifierD.go ends with All tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"io"
"os"
)
func main() {
data, _ := io.ReadAll(os.Stdin)
idx := 0
nextInt := func() int {
for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
idx++
}
val := 0
for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
val = val*10 + int(data[idx]-'0')
idx++
}
return val
}
n := nextInt()
k := nextInt()
a := make([]int, n)
mx := 0
for i := 0; i < n; i++ {
a[i] = nextInt()
if a[i] > mx {
mx = a[i]
}
}
possible := func(x int) bool {
cnt := 0
for _, v := range a {
if cnt%2 == 0 {
if v <= x {
cnt++
}
} else {
cnt++
}
if cnt >= k {
return true
}
}
cnt = 0
for _, v := range a {
if cnt%2 == 0 {
cnt++
} else {
if v <= x {
cnt++
}
}
if cnt >= k {
return true
}
}
return false
}
l, r := 1, mx
for l < r {
m := l + (r-l)/2
if possible(m) {
r = m
} else {
l = m + 1
}
}
out := bufio.NewWriter(os.Stdout)
fmt.Fprint(out, l)
out.Flush()
}