[Codeforces 985.E] Pencils and Boxes(dp,前缀和优化)

题目要求将铅笔分配到盒子里,每个盒子至少有k支铅笔,并且同一盒内的铅笔颜色饱和度差不超过d。解题思路是通过排序和动态规划来判断是否可能满足条件。dp[i]表示前i个铅笔是否能放入盒子,通过前缀和优化,可以在O(N)的时间复杂度内完成查询。
摘要由CSDN通过智能技术生成

E. Pencils and Boxes

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1,a2,...,an a 1 ,   a 2 ,   . . . ,   a n of n integer numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:

  • Each pencil belongs to exactly one box;
  • Each non-empty box has at least k k pencils in it;
  • If pencils i and j j belong to the same box, then | a i a j | d , where |x| | x | means absolute value of x x . Note that the opposite is optional, there can be pencils i and j j such that
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值