题目链接
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 nnn days. On the iii-th day, aia_iai​ loaves of bread will be baked in the morning before the opening. At the end of the nnn-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 kkk, it means that each day kkk 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 mmm possible consumer demand values k1,k2,…,kmk_1, k_2, \dots, k_mk1​,k2​,…,km​, and now he’d like to calculate the unattractiveness of the bakery for each value of demand. Can you help him?

Input

The first line contains two integers nnn and mmm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^51≤n≤2⋅105; 1≤m≤2⋅1051 \le m \le 2 \cdot 10^51≤m≤2⋅105) — the number of days the bakery is open and the number of possible values of consumer demand.

The second line contains nnn integers a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​ (1≤ai≤1091 \le a_i \le 10^91≤ai​≤109) — the number of bread loaves that will be baked each day.

The third line contains mmm integers k1,k2,…,kmk_1, k_2, \dots, k_mk1​,k2​,…,km​ (1≤k1<k2<⋯<km≤1091 \le k_1 < k_2 < \dots < k_m \le 10^91≤k1​<k2​<⋯<km​≤109) — the possible consumer demand values in the ascending order.

Output

Print mmm integers: for each consumer demand, print the unattractiveness of the bakery.

Examples

input

5 4
5 2 1 3 7
1 3 4 10

output

4 2 1 0

input

8 9
3 1 4 1 5 9 2 6
1 2 3 4 5 6 7 8 9

output

7 5 3 3 2 1 1 1 0

Note

In the first example, let’s describe what happens for couple consumer demands:

If consumer demand is equal to 111:

  • at day 111: 555 loaves are baked and only 111 is sold with spoilage equal to 1−1=01 - 1 = 01−1=0;
  • at day 222: 444 loaves are left and 222 more are baked. Only 111 loaf was sold and it was the loaf baked today with spoilage 2−2=02 - 2 = 02−2=0;
  • at day 333: 444 loaves from the first day and 111 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3−3=03 - 3 = 03−3=0;
  • at day 444: 444 loaves from the first day and 111 loaf from the second day left. 333 more loaves were baked and one of them was sold this day with spoilage 4−4=04 - 4 = 04−4=0;
  • at day 555: 444 loaves from the first day, 111 loaf from the second day and 222 loaves from the fourth day left. 777 more loaves were baked and, since it’s the last day, all 141414 loaves were sold. 444 loaves from the first day have the maximum spoilage equal to 5−1=45 - 1 = 45−1=4.

In total, the unattractiveness of the bakery will be equal to 444.

If consumer demand is equal to 101010 then all baked bread will be sold in the day it was baked and will have spoilage equal to 000.

首先将 aaa 求前缀和,然后在前缀和用单调栈预处理以每一天为结束的平均产量最高的连续天的值并按升序排序。
考虑维护一个区间集合,对于集合中的某个区间 [l,r][l,r][l,r] ,其左右端点 l,rl,rl,r 为右端点的任意区间内的平均值一定小于等于当前每天的平均花费 kkk ,而以区间 (l,r)(l,r)(l,r) 中任意一点为右端点一定能找到一个区间使得平均值大于 kkk ,因此区间 (l,r)(l,r)(l,r) 中任意一天面包一定有剩余,而区间端点处面包一定没有剩余。进一步可以得出第 l+1l+1l+1 天一定有当天面包的剩余,因此第 rrr 天一定用到了第 l+1l+1l+1 天的面包,且一定不会用到第 l+1l+1l+1 天之前的面包。因此 unattractiveness 为最长区间长度减 222。
从小到大遍历 kkk ,并维护区间即可得到答案。

#include<bits/stdc++.h>#define ll long long
#define ce(i, r) i==r?'\n':' '
#define fi first
#define se second
using namespace std;inline int qr() {int f = 0, fu = 1;char c = getchar();while (c < '0' || c > '9') {if (c == '-')fu = -1;c = getchar();}while (c >= '0' && c <= '9') {f = (f << 3) + (f << 1) + (c & 15);c = getchar();}return f * fu;
}const int N = 2e5 + 10;
pair<int, int> seq[N];
pair<int, ll> stk[N];
int n, m;
ll a[N];
set<int> st;
multiset<int> xst;inline void ins(int x) {auto it = st.lower_bound(x);int r = *it, l = *--it;xst.erase(xst.find(r - l));xst.insert(r - x), xst.insert(x - l);st.insert(x);
}int main() {n = qr(), m = qr();for (int i = 1; i <= n; i++)a[i] = a[i - 1] + qr();for (int i = 1, t = 1; i <= n - 1; i++) {while (t >= 2 && (__int128) (a[i] - stk[t].se) * (i - stk[t - 1].fi) <=(__int128) (a[i] - stk[t - 1].se) * (i - stk[t].fi))t--;seq[i] = {(a[i] - stk[t].se - 1) / (i - stk[t].fi) + 1, i}, stk[++t] = {i, a[i]};}seq[n] = {INT_MAX, n};sort(seq + 1, seq + n);st.insert(0), st.insert(n), xst.insert(n);for (int i = 1, now = 1; i <= m; i++) {int v = qr();while (v >= seq[now].fi)ins(seq[now++].se);printf("%d%c", *--xst.end() - 1, ce(i, m));}return 0;
}

2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest B. Bakery相关推荐

  1. 2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest Smash the Trash(二分)

    2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest Smash the Trash(二分) 链接 题意: 思路:二分答案 ...

  2. 2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest X-Magic Pair(gcd)

    2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest X-Magic Pair(gcd) 链接 题意:给出a,b,有两种选 ...

  3. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest 部分题解ABFHJLN

    2020-10-10为了准备CCPC,师兄下午拉了场ICPC练习让我们模拟,负责读题的菜鸡晚上回来重新做了模拟场上有思路的题QAQ 文章目录 A - Berstagram B - The Feast ...

  4. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest K. The Robot

    翻译: 有一个机器人在一个没有尽头的方格场上.最初,机器人位于坐标为(0,0)的单元中.他将执行由一串大写拉丁字母"L"."R"."D".& ...

  5. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest

    A.Berstagram 题意:起始数列是1,2,3,--,n,给你m个操作x,表示将数字x和前一个位置的数交换,如果已经在第一个则不做操作,求每个数能到达的位置的最大和最小值: 分析:扫一遍模拟,更 ...

  6. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest B. The Feast and the Bus (经典贪心)

    题目链接 思路:先把k个团队的人数从大到小排序,我们发现s最小是num[1],那么s最大是num[1]+num[2]?可是我们这样想的话容易被毒瘤数据tle,所以还得优化一下,我们可以想我们最优的方案 ...

  7. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest A. LaIS

    题目链接 Let's call a sequence b1,b2,b3-,bk−1,bkb_1, b_2, b_3 \dots, b_{k - 1}, b_kb1​,b2​,b3​-,bk−1​,bk ...

  8. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest J. The Parade(二分)

    题目链接 题意:给定身高为1-n的士兵数量,现在要求士兵分成k排,要求每一排士兵身高差不能超过1,求最多有多少士兵可以拿出来排. 思路:又是一个裸的二分题,但是写check函数的时候确遇到了bug.. ...

  9. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest J. The Parade(二分+贪心)

    题目链接 大意:给你一个组士兵,告诉你身高iii的人数aia_iai​,让你放在kkk行,使得每行人数相同且每行中士兵身高差不超过111,问你最多能放多少士兵满足条件. 思路:二分每行人数.证明:如果 ...

最新文章

  1. 使用Logstash同步MySQL数据库信息到ElasticSearch
  2. LeetCode算法题0:分发糖果【贪心算法】
  3. Leetcode_198_House Robber
  4. 如何跟踪log4j漏洞原理及发现绕WAF的tips
  5. 金三银四的腾讯、阿里、​字节等大厂前端社招面经
  6. VB数据库经典实例总结(二)
  7. 数据库中复合主键与联合主键
  8. c# mysql 连接类_c#中连接数据库的类怎么写呀?
  9. 微信多开txt_1分钟教你如何实现微信多开!建议收藏!
  10. unity 入门学习之(一)创建基本的3D游戏场景
  11. Kubernetes系列——Kubernetes 组件、对象(二)
  12. typecho插件:用访问量统计插件
  13. elementui 表格序号el-table自定义序号事件
  14. gpu内存大小 android,Android性能测试(内存、cpu、fps、流量、GPU、电量)——adb篇...
  15. marshmallow——自定义类型
  16. scp在命令行中带密码远程拷贝文件
  17. 驰为 hi12 linux,PC商务体验 Intel四核平板驰为Hi12评测
  18. 职业规划 思维导图
  19. 如何给图片标注重点(加红框、箭头等)\一些好用的快捷键
  20. python多线程批量过滤文件关键字

热门文章

  1. Anaconda介绍、【windows版】下载、安装及使用教程
  2. Windows Phone 8 新篇章(1):先把牛皮吹破
  3. 12x12怎么速算_让人说你好聪明哦!一个速算的诀窍,2位数x2位数的快捷心算
  4. Microsoft Lookback Adapter添加并设置回环网卡(转)
  5. 正待等待暴雪服务器响应,暴雪玩乌龙,TBC怀旧服B测服务器未部署,或将增设跃迁兽坐骑...
  6. iOS投屏搜索不到设备如何解决?投屏怎么设置?
  7. 全球最大的局域网--可怜的大陆网民
  8. matplotlib绘制无法显示xlabel与ylabel中文标签
  9. 基于python的网上商城系统 python数码商城系统
  10. ubuntu系统一键安装docker环境