← Home
For problem statement at 1000-1999/1800-1899/1800-1809/1800/problemC1.txt this is a correct solution, but verifier at 1000-1999/1800-1899/1800-1809/1800/verifierC1.go ends with All tests passed can you fix the verifier? package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type MinHeap []int64

func (h MinHeap) Len() int            { return len(h) }
func (h MinHeap) Less(i, j int) bool  { return h[i] < h[j] }
func (h MinHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *MinHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *MinHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[:n-1]
	return x
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		h := &MinHeap{}
		heap.Init(h)
		var sum int64
		zeros := 0

		for i := n - 1; i >= 0; i-- {
			if a[i] == 0 {
				zeros++
			} else {
				heap.Push(h, a[i])
				sum += a[i]
				if h.Len() > zeros {
					sum -= heap.Pop(h).(int64)
				}
			}
		}

		fmt.Fprintln(out, sum)
	}
}