For problem statement at 2000-2999/2000-2099/2040-2049/2046/problemE1.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2040-2049/2046/verifierE1.go ends with All 18 tests passed. can you fix the verifier? package main
import (
"bytes"
"io"
"os"
)
type Part struct {
a int
b int
s int
}
var data []byte
var ptr int
func nextInt() int {
for ptr < len(data) && (data[ptr] < '0' || data[ptr] > '9') {
ptr++
}
x := 0
for ptr < len(data) && data[ptr] >= '0' && data[ptr] <= '9' {
x = x*10 + int(data[ptr]-'0')
ptr++
}
return x
}
func writeInt(out *bytes.Buffer, x int) {
if x == 0 {
out.WriteByte('0')
return
}
var buf [20]byte
n := 0
for x > 0 {
buf[n] = byte('0' + x%10)
x /= 10
n++
}
for i := n - 1; i >= 0; i-- {
out.WriteByte(buf[i])
}
}
func main() {
data, _ = io.ReadAll(os.Stdin)
t := nextInt()
var out bytes.Buffer
for ; t > 0; t-- {
n := nextInt()
m := nextInt()
parts := make([]Part, n+1)
used := make(map[int]struct{}, n+4)
for i := 1; i <= n; i++ {
a := nextInt()
b := nextInt()
s := nextInt()
parts[i] = Part{a: a, b: b, s: s}
used[s] = struct{}{}
}
var city1, city2 []int
for c := 0; c < m; c++ {
k := nextInt()
if c == 0 {
city1 = make([]int, k)
for i := 0; i < k; i++ {
city1[i] = nextInt()
}
} else if c == 1 {
city2 = make([]int, k)
for i := 0; i < k; i++ {
city2[i] = nextInt()
}
} else {
for i := 0; i < k; i++ {
nextInt()
}
}
}
A := parts[city1[0]].a
for _, id := range city1[1:] {
if parts[id].a < A {
A = parts[id].a
}
}
B := parts[city2[0]].a
for _, id := range city2[1:] {
if parts[id].a > B {
B = parts[id].a
}
}
if A > B {
dummy := 1000000000
for {
if _, ok := used[dummy]; !ok {
break
}
dummy--
}
writeInt(&out, 1)
out.WriteByte('\n')
writeInt(&out, A)
out.WriteByte(' ')
writeInt(&out, dummy)
out.WriteByte('\n')
continue
}
block := make(map[int]int)
for _, id := range city2 {
p := parts[id]
if p.a >= A {
if v, ok := block[p.s]; !ok || p.b > v {
block[p.s] = p.b
}
}
}
specNeed := make(map[int]int)
ok := true
hasStrong := false
for _, id := range city1 {
p := parts[id]
if p.a > B {
hasStrong = true
continue
}
limit := B
if v, exists := block[p.s]; exists && v > limit {
limit = v
}
if p.b <= limit {
ok = false
break
}
specNeed[p.s] = limit + 1
}
if !ok {
out.WriteByte('-')
out.WriteByte('1')
out.WriteByte('\n')
continue
}
needDummies := 1
if hasStrong {
needDummies = 2
}
dummies := make([]int, 0, needDummies)
cand := 1000000000
for len(dummies) < needDummies {
if _, exists := used[cand]; !exists {
dummies = append(dummies, cand)
used[cand] = struct{}{}
}
cand--
}
total := 1 + len(specNeed)
if hasStrong {
total++
}
writeInt(&out, total)
out.WriteByte('\n')
writeInt(&out, A)
out.WriteByte(' ')
writeInt(&out, dummies[0])
out.WriteByte('\n')
if hasStrong {
writeInt(&out, B+1)
out.WriteByte(' ')
writeInt(&out, dummies[1])
out.WriteByte('\n')
}
for s, d := range specNeed {
writeInt(&out, d)
out.WriteByte(' ')
writeInt(&out, s)
out.WriteByte('\n')
}
}
os.Stdout.Write(out.Bytes())
}