package main
import "fmt"
func distributeCandies(candies []int, kids []int) []int {
// 计算每个孩子可以得到的饼干数量
max := 0
for _, candy := range candies {
if candy >= kids[0] {
max = max + 1
}
}
// 如果每个孩子可以得到的饼干数量小于等于 0,则返回空
if max <= 0 {
return []int{}
}
// 分配饼干
result := make([]int, len(kids))
for i := range kids {
if kids[i] <= candies[0] {
result[i] = kids[i]
} else {
result[i] = candies[0]
for j := 1; j < len(candies); j++ {
if kids[i] <= candies[j] {
result[i] += candies[j]
candies[j] = 0
} else {
candies[j] -= kids[i] - candies[j]
}
}
}
}
// 返回分配结果
return result
}
func main() {
candies := []int{3, 2, 1, 3}
kids := []int{2, 1, 1, 2}
result := distributeCandies(candies, kids)
fmt.Println(result)
}