CF1468B.Bakery
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops.
Monocarp plans that the bakery will work for n days. On the i-th day, ai loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount.
Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors.
Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery.
Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness).
Monocarp analyzed his competitors' data and came up with m possible consumer demand values k1,k2,…,km, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him?
Monocarp 想在当地开一家面包店。但首先,他需要判断自己是否能与其它店铺竞争。
Monocarp 计划该面包店运营 n 天。在第 i 天清晨开门前,将烘烤 ai 个面包。到第 n 天结束时,Monocarp 将以大幅折扣售出所有此前未售出的剩余面包。
由于面包的储存方式,店员按如下顺序销售面包:首先销售当天清晨新烘烤的面包;其次销售前一天烘烤且尚未售出的面包;然后销售两天前烘烤且尚未售出的面包,依此类推。因此,部分顾客可能买到较为陈旧的面包,并必然传播负面评价。
我们定义一个面包的“变质天数”为它被售出的日期与被烘烤的日期之差。那么,该面包店的“不吸引力值”即为所有在该店烘烤的面包中最大的变质天数。
假设 Monocarp 所在地区的消费者需求为 k,即每天恰好有 k 位顾客光顾面包店,每位顾客购买一个面包(面包按上述顺序销售)。若当日无剩余面包,则该顾客不购买任何东西。在最后一天的清仓销售中,所有剩余面包均会被售出(这些面包仍参与不吸引力值的计算)。
Monocarp 分析了竞争对手的数据,得到了 m 个可能的消费者需求值 k1,k2,…,km,现在他希望针对每个需求值计算面包店的不吸引力值。你能帮他完成吗?
输入格式
The first line contains two integers n and m (1≤n≤2⋅105; 1≤m≤2⋅105) — the number of days the bakery is open and the number of possible values of consumer demand.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the number of bread loaves that will be baked each day.
The third line contains m integers k1,k2,…,km (1≤k1<k2<⋯<km≤109) — the possible consumer demand values in the ascending order.
第一行包含两个整数 n 和 m(1≤n≤2⋅105;1≤m≤2⋅105)—— 分别表示面包店营业的天数以及消费者需求可能取值的个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 表示每天将烘烤的面包数量。
第三行包含 m 个整数 k1,k2,…,km(1≤k1<k2<⋯<km≤109)—— 表示按升序排列的消费者需求所有可能取值。
输出格式
Print m integers: for each consumer demand, print the unattractiveness of the bakery.
输出 m 个整数:对每个消费者需求,输出该面包店的“不吸引力”值。
输入输出样例
输入#1
5 4 5 2 1 3 7 1 3 4 10
输出#1
4 2 1 0
输入#2
8 9 3 1 4 1 5 9 2 6 1 2 3 4 5 6 7 8 9
输出#2
7 5 3 3 2 1 1 1 0
说明/提示
In the first example, let's describe what happens for couple consumer demands:
If consumer demand is equal to 1:
- at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1−1=0;
- at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2−2=0;
- at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3−3=0;
- at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4−4=0;
- at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5−1=4.
In total, the unattractiveness of the bakery will be equal to 4.
If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0.
在第一个例子中,我们来描述几组消费者需求下的情况:
如果消费者需求等于 1:
- 第 1 天:烤制 5 条面包,仅售出 1 条,变质量为 1−1=0;
- 第 2 天:剩余 4 条面包,并新烤制 2 条;当天仅售出 1 条,且为当日新烤制的面包,变质量为 2−2=0;
- 第 3 天:剩余第 1 天的 4 条面包和第 2 天的 1 条面包;当日再烤制 1 条并售出,变质量为 3−3=0;
- 第 4 天:剩余第 1 天的 4 条面包和第 2 天的 1 条面包;当日再烤制 3 条,其中 1 条于当日售出,变质量为 4−4=0;
- 第 5 天:剩余第 1 天的 4 条面包、第 2 天的 1 条面包以及第 4 天的 2 条面包;当日再烤制 7 条面包,且由于是最后一天,全部 14 条面包均被售出;其中第 1 天的 4 条面包变质量最大,为 5−1=4。
总计,该面包店的“不吸引力”值为 4。
如果消费者需求等于 10,则所有当天烤制的面包均会在当日售出,变质量均为 0。
输入解题思路,AI测评打分。不知道怎么写?