← Home
For problem statement at 0-999/500-599/570-579/572/problemB.txt this is a correct solution, but verifier at 0-999/500-599/570-579/572/verifierB.go ends with All tests passed can you fix the verifier? package main

import (
	"fmt"
	"sort"
)

type Order struct {
	p, q int
}

func main() {
	var n, s int
	if _, err := fmt.Scan(&n, &s); err != nil {
		return
	}

	buyMap := make(map[int]int)
	sellMap := make(map[int]int)

	for i := 0; i < n; i++ {
		var dir string
		var p, q int
		fmt.Scan(&dir, &p, &q)
		if dir == "B" {
			buyMap[p] += q
		} else if dir == "S" {
			sellMap[p] += q
		}
	}

	var buys []Order
	for p, q := range buyMap {
		buys = append(buys, Order{p, q})
	}
	var sells []Order
	for p, q := range sellMap {
		sells = append(sells, Order{p, q})
	}

	sort.Slice(sells, func(i, j int) bool { return sells[i].p < sells[j].p })
	sort.Slice(buys, func(i, j int) bool { return buys[i].p > buys[j].p })

	sellCount := s
	if len(sells) < s {
		sellCount = len(sells)
	}
	for i := sellCount - 1; i >= 0; i-- {
		fmt.Printf("S %d %d\n", sells[i].p, sells[i].q)
	}

	buyCount := s
	if len(buys) < s {
		buyCount = len(buys)
	}
	for i := 0; i < buyCount; i++ {
		fmt.Printf("B %d %d\n", buys[i].p, buys[i].q)
	}
}