lc-go/solutions/23/q2300/solution.go
2026-01-25 11:56:12 +09:00

32 lines
505 B
Go

package q2300
import "slices"
func nGte(arr []int, target int) int {
l, r := 0, len(arr)
for l < r {
m := (l + r) / 2
if arr[m] >= target {
r = m
} else {
l = m + 1
}
}
return len(arr) - l
}
func successfulPairs(spells []int, potions []int, success int64) []int {
slices.Sort(potions)
for i := range spells {
pow := spells[i]
want := int(success) / pow
if pow*want < int(success) {
want++
}
spells[i] = nGte(potions, want)
}
return spells
}
var _ = successfulPairs