LeetCode每日一题(2305. Fair Distribution of Cookies)

给定包含不同数量饼干的袋子和要分配的孩子数,找出所有分配方式中最大值最小的不公平分布。例如,cookies=[8,15,10,20,8],k=2时,不公平度最小为31。问题需要考虑如何有效地枚举分配策略以找到最小不公平度。" 113198133,10504225,Ubuntu系统通过SSH服务连接指南,"['Linux', 'Ubuntu', 'SSH']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.

The unfairness of a distribution is defined as the maximum total cookies obtained by a single child in the distribution.

Return the minimum unfairness of all distributions.

Example 1:

Input: cookies = [8,15,10,20,8], k = 2
Output: 31

Explanation: One optimal distribution is [8,15,8] and [10,20]

  • The 1st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.
  • The 2nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.
    The unfairness of the distribution is max(31,30) = 31.
    It can be shown that there is no distribution with an unfairness less than 31.

Example 2:

Input: cookies = [6,1,3,2,2,4,1,2], k = 3
Output: 7

Explanation: One optimal distribution is [6,1], [3,2,2], and [4,1,2]

  • The 1st child receives [6,1] which has a total of 6 + 1 = 7 cookies.
  • The 2nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.
  • The 3rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.
    The unfairness of the distribution is max(7,7,7) = 7.
    It can be shown that there is no distribution with
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值