← Home
For problem statement at 1000-1999/1300-1399/1370-1379/1379/problemC.txt this is a correct solution, but verifier at 1000-1999/1300-1399/1370-1379/1379/verifierC.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"io"
	"os"
	"sort"
	"strconv"
)

type Pair struct {
	a, b int64
}

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	var pos int
	readInt := func() int64 {
		for pos < len(buf) && buf[pos] <= ' ' {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		var res int64
		for pos < len(buf) && buf[pos] > ' ' {
			res = res*10 + int64(buf[pos]-'0')
			pos++
		}
		return res
	}

	t := int(readInt())
	var out []byte
	for tc := 0; tc < t; tc++ {
		n := readInt()
		m := int(readInt())

		flowers := make([]Pair, m)
		aVals := make([]int64, m)
		for i := 0; i < m; i++ {
			flowers[i].a = readInt()
			flowers[i].b = readInt()
			aVals[i] = flowers[i].a
		}

		sort.Slice(aVals, func(i, j int) bool {
			return aVals[i] > aVals[j]
		})

		pref := make([]int64, m+1)
		for i := 0; i < m; i++ {
			pref[i+1] = pref[i] + aVals[i]
		}

		var maxAns int64 = 0
		if int64(m) >= n {
			maxAns = pref[n]
		}

		for i := 0; i < m; i++ {
			a := flowers[i].a
			b := flowers[i].b

			left, right := 0, m
			for left < right {
				mid := left + (right-left)/2
				if aVals[mid] >= b {
					left = mid + 1
				} else {
					right = mid
				}
			}
			c := int64(left)
			if c > n {
				c = n
			}

			var ans int64
			if a >= b {
				ans = pref[c] + (n-c)*b
			} else {
				if c == n {
					ans = pref[n]
				} else {
					ans = pref[c] + a + (n-c-1)*b
				}
			}
			if ans > maxAns {
				maxAns = ans
			}
		}
		out = strconv.AppendInt(out, maxAns, 10)
		out = append(out, '\n')
	}
	os.Stdout.Write(out)
}
```