← Home
For problem statement at 1000-1999/1900-1999/1960-1969/1969/problemD.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1960-1969/1969/verifierD.go ends with All 100 tests passed can you fix the verifier? ```go
package main

import (
	"container/heap"
	"fmt"
	"io"
	"os"
	"sort"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x any)        { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() any {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

type Item struct {
	a, b int
}

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	var pos int

	nextInt := func() int {
		for pos < len(buf) && (buf[pos] < '0' || buf[pos] > '9') {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		res := 0
		for pos < len(buf) && buf[pos] >= '0' && buf[pos] <= '9' {
			res = res*10 + int(buf[pos]-'0')
			pos++
		}
		return res
	}

	t := nextInt()
	for tc := 0; tc < t; tc++ {
		n := nextInt()
		k := nextInt()

		items := make([]Item, n)
		for i := 0; i < n; i++ {
			items[i].a = nextInt()
		}
		for i := 0; i < n; i++ {
			items[i].b = nextInt()
		}

		sort.Slice(items, func(i, j int) bool {
			if items[i].b == items[j].b {
				return items[i].a < items[j].a
			}
			return items[i].b > items[j].b
		})

		if k == 0 {
			var ans int64 = 0
			for i := 0; i < n; i++ {
				if items[i].b > items[i].a {
					ans += int64(items[i].b - items[i].a)
				}
			}
			fmt.Println(ans)
			continue
		}

		suffixSum := make([]int64, n+1)
		for i := n - 1; i >= 0; i-- {
			diff := int64(items[i].b - items[i].a)
			if diff < 0 {
				diff = 0
			}
			suffixSum[i] = suffixSum[i+1] + diff
		}

		h := &IntHeap{}
		heap.Init(h)
		var sum int64 = 0
		var ans int64 = 0

		for i := 0; i < n; i++ {
			heap.Push(h, items[i].a)
			sum += int64(items[i].a)

			if h.Len() > k {
				maxA := heap.Pop(h).(int)
				sum -= int64(maxA)
			}

			if h.Len() == k {
				curr := suffixSum[i+1] - sum
				if curr > ans {
					ans = curr
				}
			}
		}

		fmt.Println(ans)
	}
}
```