For problem statement at 1000-1999/1700-1799/1770-1779/1776/problemD.txt this is a correct solution, but verifier at 1000-1999/1700-1799/1770-1779/1776/verifierD.go ends with Test 2 failed
Input:0 3 1 17
Expected:4
1 0 3
2 0 4
3 2 5
1 3 6
Got:4
1 0 3
2 1 4
3 2 5
1 3 7
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
type Task struct {
p, q int
cid int
}
func main() {
var a, b, c, l int
in := bufio.NewReader(os.Stdin)
fmt.Fscan(in, &a, &b, &c, &l)
usage := make([]int, l+5)
endUsed := make([]bool, l+5)
var tasks []Task
schedule := func(limit int, duration int) {
count := 0
ptr := duration
for count < limit && ptr <= l {
if !endUsed[ptr] {
canFit := true
for t := ptr - duration; t < ptr; t++ {
if usage[t] >= 3 {
canFit = false
break
}
}
if canFit {
endUsed[ptr] = true
for t := ptr - duration; t < ptr; t++ {
usage[t]++
}
tasks = append(tasks, Task{p: ptr - duration, q: ptr})
count++
}
}
ptr++
}
}
schedule(a, 2)
schedule(b, 3)
schedule(c, 4)
sort.Slice(tasks, func(i, j int) bool {
return tasks[i].p < tasks[j].p
})
freeUntil := []int{0, 0, 0, 0}
for i := range tasks {
assigned := -1
for k := 1; k <= 3; k++ {
if freeUntil[k] <= tasks[i].p {
assigned = k
break
}
}
tasks[i].cid = assigned
freeUntil[assigned] = tasks[i].q
}
sort.Slice(tasks, func(i, j int) bool {
return tasks[i].q < tasks[j].q
})
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
fmt.Fprintln(out, len(tasks))
for _, t := range tasks {
fmt.Fprintf(out, "%d %d %d\n", t.cid, t.p, t.q)
}
}
```