During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added:

— We have a contract. A rental agreement. He always works all day long. He likes silence. Besides that, there are many more advantages of living here in the Castle. Say, it is easy to justify a missed call: a phone ring can't reach the other side of the Castle from where the phone has been left. So, the imprisonment is just a tale. Actually, he thinks about everything. He is smart. For instance, he started replacing incandescent lamps with energy-saving lamps in the whole Castle...

Lpl chose a model of energy-saving lamps and started the replacement as described below. He numbered all rooms in the Castle and counted how many lamps in each room he needs to replace.

At the beginning of each month, Lpl buys mm energy-saving lamps and replaces lamps in rooms according to his list. He starts from the first room in his list. If the lamps in this room are not replaced yet and Lpl has enough energy-saving lamps to replace all lamps, then he replaces all ones and takes the room out from the list. Otherwise, he'll just skip it and check the next room in his list. This process repeats until he has no energy-saving lamps or he has checked all rooms in his list. If he still has some energy-saving lamps after he has checked all rooms in his list, he'll save the rest of energy-saving lamps for the next month.

As soon as all the work is done, he ceases buying new lamps. They are very high quality and have a very long-life cycle.

Your task is for a given number of month and descriptions of rooms to compute in how many rooms the old lamps will be replaced with energy-saving ones and how many energy-saving lamps will remain by the end of each month.

Input

Each input will consist of a single test case.

The first line contains integers nn and m (1 \le n \le 100000, 1 \le m \le 100)m(1≤n≤100000,1≤m≤100) — the number of rooms in the Castle and the number of energy-saving lamps, which Lpl buys monthly.

The second line contains nn integers k_1, k_2, ..., k_nk1​,k2​,...,kn​
(1 \le k_j \le 10000, j = 1, 2, ..., n)(1≤kj​≤10000,j=1,2,...,n) — the number of lamps in the rooms of the Castle. The number in position jj is the number of lamps in jj-th room. Room numbers are given in accordance with Lpl's list.

The third line contains one integer q (1 \le q \le 100000)q(1≤q≤100000) — the number of queries.

The fourth line contains qq integers d_1, d_2, ..., d_qd1​,d2​,...,dq​
(1 \le d_p \le 100000, p = 1, 2, ..., q)(1≤dp​≤100000,p=1,2,...,q) — numbers of months, in which queries are formed.

Months are numbered starting with 11; at the beginning of the first month Lpl buys the first m energy-saving lamps.

Output

Print qq lines.

Line pp contains two integers — the number of rooms, in which all old lamps are replaced already, and the number of remaining energy-saving lamps by the end of d_pdp​ month.

Hint

Explanation for the sample:

In the first month, he bought 44 energy-saving lamps and he replaced the first room in his list and remove it. And then he had 11 energy-saving lamps and skipped all rooms next. So, the answer for the first month is 1,1------11,1−−−−−−1 room's lamps were replaced already, 11 energy-saving lamp remain.

样例输入复制

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

样例输出复制

4 0
1 1
3 6
5 1
5 1
2 0
3 2
4 4
3 6
5 1
#include <iostream>
#include<cstdio>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn =+;
int a[maxn],b[maxn];
int sumv[maxn << ];
struct node
{
int x,y;
};
node lamp[maxn];
void pushup(int o)
{
sumv[o]=min(sumv[o<<],sumv[o<<|]);
}
void build(int o,int l,int r)
{
if(l==r)
{
sumv[o]=a[l];
return ;
}
int mid=(l+r) >> ;
build(o<<,l,mid);
build(o<<|,mid+,r);
pushup(o);
} void change(int o,int l,int r,int q,int v)
{
if(l==r)
{
sumv[o]=v;
return ;
}
int mid=(l+r)>>;
if(q<=mid) change(o<<,l,mid,q,v);
else
change(o<<|,mid+,r,q,v);
pushup(o);
} int find1(int o,int l,int r,int k)
{
if(sumv[o]>k) return ;
if(l==r)
{
return l;
}
int mid=(l+r)>>;
if(sumv[o<<]<=k) return find1(o<<,l,mid,k);
else if(sumv[o<<|]<=k) return find1(o<<|,mid+,r,k);
} int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int q;
scanf("%d",&q);
int maxnum=;
for(int i=;i<=q;i++)
{
scanf("%d",&b[i]);
maxnum=max(maxnum,b[i]);
}
build(,,n);
int num1=,num2=,cnt;
for(int i=;i<=maxnum;i++)
{
if(num1<n)
num2+=m;
while(cnt=find1(,,n,num2))
{
num2-=a[cnt];
change(,,n,cnt,INF);
num1++;
}
lamp[i].x=num1,lamp[i].y=num2;
}
for(int i=;i<=q;i++)
printf("%d %d\n",lamp[b[i]].x,lamp[b[i]].y);
return ;
}

Lpl and Energy-saving Lamps的更多相关文章

  1. CF GYM 100703B Energy Saving

    题意:王子每月买m个灯泡给n个房间换灯泡,如果当前有的灯泡数够列表的第一个房间换的就全换,直到灯泡不够为止,给出q个查询,查询x月已经换好几个房子,手里还剩多少灯泡. 解法:水题……小模拟. 代码: ...

  2. ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  3. 计蒜客 30996 - Lpl and Energy-saving Lamps - [线段树][2018ICPC南京网络预赛G题]

    题目链接:https://nanti.jisuanke.com/t/30996 During tea-drinking, princess, amongst other things, asked w ...

  4. 南京网络赛G-Lpl and Energy【线段树】

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  5. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  6. Ultra-Thin LED Downlight Selection: 6 Things

    LED Decorative Light Manufacturer    description: ultra-thin LED downlight features can maintain the ...

  7. LED Decorative Light Supplier Introduction - LED Track Light Products

    LED Decorative Light Supplier    introduction: LED track light is a track light with LED as the ligh ...

  8. LED Decorative Light Manufacturer - Led Wall Lamp Performance Characteristics

    LED Decorative Light Manufacturer    introduction: LED wall lamp is a light-emitting diode as a ligh ...

  9. 【总结】在VirtualBox上面安装Mac的注意事项

    看此文之前 http://www.crifan.com/category/work_and_job/virtual_machine/virtualbox-virtual_machine/ 此文仅仅是针 ...

随机推荐

  1. 可决系数R^2和方差膨胀因子VIF

    然而很多时候,被筛选的特征在模型上线的预测效果并不理想,究其原因可能是由于特征筛选的偏差. 但还有一个显著的因素,就是选取特征之间之间可能存在高度的多重共线性,导致模型对测试集预测能力不佳. 为了在筛 ...

  2. python装饰器的简单理解

    如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖. 装饰器的使用方法很固定: 先定义一个装饰函数(帽子)(也可以用类.偏函数实现) 再定义你 ...

  3. OCP内容

    安装 --网络 --存储 --用户 --对象 --ASM (包含前面的内容的复习)--内存管理 -- 备份 --闪回 -- 事务 --sql 编程

  4. NOIP模拟赛(by hzwer) T2 小奇的序列

    [题目背景] 小奇总是在数学课上思考奇怪的问题. [问题描述] 给定一个长度为 n 的数列,以及 m 次询问,每次给出三个数 l,r 和 P, 询问 (a[l'] + a[l'+1] + ... + ...

  5. codevs 4064 组合 x

    很久之前发过啦~不过删掉了...再发一下 4064 组合 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 组合就 ...

  6. R语言预测实战(第二章--预测方法论)

    2.1预测流程 从确定预测主题开始,一次进行数据收集.选择方法.分析规律.建立模型.评估效果直到发布模型. 2.2.1确定主题 (1)指标:表达的是数量特征,预测的结果也通常是通过指标的取值来体现. ...

  7. 170903-关于MyBatis

    MyBatis总体介绍:  MyBatis实际上是Ibatis3.0版本以后的持久化层框架[也就是和数据库打交道的框架]! 和数据库打交道的技术有: 原生的JDBC技术--->Spring的Jd ...

  8. 个推一键认证SDK重磅推出,打造秒级登录体验,让用户一“键”倾心

    移动互联网时代,用户注意力的持续时间越来越短,他们追求便捷与高效.从账号密码登录.短信验证,到第三方登录甚至人脸识别登录,APP的注册/登录方式在逐步变化,开发者希望在这重要的交互端口提升用户的体验, ...

  9. 【Geek议题】合理的VueSPA架构讨论(下)

    接上篇<[Geek议题]合理的VueSPA架构讨论(上)>传送门. 自动化维护登录状态 登录状态标识符跟token类似,都是需要自动维护有效期,但也有些许不同,获取过程只在用户登录或注册的 ...

  10. cefsharp 在高DPI下闪烁的问题

    今天有客户朋友说程序在他的surface下界面很闪烁,搜索了相关的资料,初步判定是DPI引起的问题,但也有可能是cefsharp 51版本在WIN10上面没有禁用GPU加速,苦于没有环境测试,所以抱着 ...