add new solutions

This commit is contained in:
Yiyang Kang 2026-03-13 16:18:54 +09:00
parent f249852923
commit f297e11859
Signed by: kkyy
SSH key fingerprint: SHA256:lJSbAzC3MvrSORdvIVK6h/3g+rVKJNzM7zq0MgA9WKY
10 changed files with 373 additions and 0 deletions

View file

@ -0,0 +1,37 @@
// Package q3296 implements a solution for https://leetcode.com/problems/minimum-number-of-seconds-to-make-mountain-height-zero/
package q3296
import (
"math"
"slices"
)
func canFinishIn(mHeight int, wTimes []int, secs int) bool {
decHeight := 0
for _, t := range wTimes {
h := int(math.Sqrt(float64(secs) * 2 / float64(t)))
if t*h*(h+1)/2 > secs {
h--
}
decHeight += h
}
return decHeight >= mHeight
}
func minNumberOfSeconds(mountainHeight int, workerTimes []int) int64 {
worse := slices.Max(workerTimes) * (mountainHeight + 1) * mountainHeight / 2
l, r := 0, worse+1
for l < r {
m := (l + r) / 2
if canFinishIn(mountainHeight, workerTimes, m) {
r = m
} else {
l = m + 1
}
}
return int64(l)
}
var _ = minNumberOfSeconds