Berry Picking(思维)

题目描述
Bessie and her little sister Elsie are picking berries in Farmer John’s berry patch. Farmer John’s patch has exactly N berry trees (1≤N≤1000); tree i contains exactly Bi berries (1≤Bi≤1000). Bessie has exactly K baskets (1≤K≤1000, K even). Each basket can hold as many berries from a single tree as Bessie wants, but cannot contain berries from two different trees as their flavors will clash with each other. Baskets may remain empty.
Bessie wants to maximize the number of berries she collects. However, Farmer John wants Bessie to share with her little sister, and so Bessie will have to give Elsie the K/2 baskets with the largest number of berries. This means that Elsie may even end up with more berries than Bessie, which is very unfair, but unfortunately, sibling dynamics are not always fair.

Help Bessie figure out the maximum number of berries she can collect.

输入
The first line of input contains space-separated integers N and K.
The second line contains N space-separated integers B1,B2,…,BN.

输出
A single line with the answer.

样例输入
5 4
3 6 8 4 2

样例输出
8

提示
If Bessie fills
·one basket with 6 berries from tree 2
·two baskets, each with 4 berries from tree 3
·one basket with 4 berries from tree 4
then she receives two baskets each with 4 berries, giving her 8 berries in total.

思路
对于每种取法,其都具有一个基础值x,且x在[1,maxb]之间,枚举区间内的每一个x,即可得到其能取到的所有桶数temp,若temp<k/2,那么Bessie能拿到的个数恒等于0,那么就不需要对之后的值进行遍历,若temp>k/2 且 temp<k,这个区间内的值为所取得的(temp-k/2)*x+能用剩下的桶装下的剩余的果子,当temp>=k时,能拿到的个数为x*(k/2)

代码实现

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
嵌入式脚本berry是一种轻量级的脚本语言,它专为嵌入式系统和小型设备而设计。berry的设计目标是提供一种简单易用且资源占用较低的脚本语言,以帮助开发人员在嵌入式系统中实现脚本化的功能。 berry具有以下特点: 1. 简洁易学:berry采用类似于C语言的语法风格,易于理解和掌握。它支持常见的编程概念,如变量、条件语句、循环、函数等,开发人员可以快速上手。 2. 资源占用低:berry被设计为轻量级的脚本语言,它的解释器非常紧凑,可以运行在内存有限的嵌入式系统上。它消耗的系统资源少,对嵌入式设备的存储空间和性能要求较低。 3. 可嵌入性强:berry提供了一个可嵌入的解释器,可以方便地将它集成到嵌入式系统中,与其他编程语言或操作系统进行交互。这样,开发人员可以通过编写berry脚本,来实现系统的自动化控制、功能扩展等需求。 4. 扩展性好:berry支持扩展功能,可以通过定义和加载扩展模块,来增加语言的功能和使用能力。开发人员可以根据自己的需求,自定义和添加新的库函数和数据类型。 5. 跨平台:berry的解释器可以在多个平台上运行,包括嵌入式系统、Windows、Linux等。这意味着开发人员可以在不同的平台之间共享和利用berry脚本,提高开发效率。 总之,嵌入式脚本berry是一种简单易用、资源占用低的脚本语言,适用于嵌入式系统和小型设备的开发。它提供了良好的可嵌入性和扩展性,方便开发人员编写脚本以实现系统的自动化控制和功能扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值