← Home
For problem statement at 0-999/300-399/360-369/367/problemC.txt this is a correct solution, but verifier at 0-999/300-399/360-369/367/verifierC.go ends with All tests passed can you fix the verifier? package main

import (
	"fmt"
	"io"
	"os"
	"sort"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	idx := 0
	nextInt := func() int {
		for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
			idx++
		}
		val := 0
		for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
			val = val*10 + int(data[idx]-'0')
			idx++
		}
		return val
	}

	n := int64(nextInt())
	m := nextInt()

	ws := make([]int, m)
	for i := 0; i < m; i++ {
		_ = nextInt()
		ws[i] = nextInt()
	}

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

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

	kmax := 0
	for k := 1; k <= m; k++ {
		kk := int64(k)
		need := kk * (kk - 1) / 2
		if k%2 == 1 {
			need++
		} else {
			need += kk / 2
		}
		if need > n {
			break
		}
		kmax = k
	}

	fmt.Print(pref[kmax])
}