## 描述

传送门：我是传送门

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.

### 输入

Each input will consist of a single test case.

The first line contains integers $n$ and$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 $j-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 $1$; at the beginning of the first month Lpl buys the first m energy-saving lamps.

### 输出

Print $q$ lines.

Line $p$ 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_p$ month.

### 样例

#### 输入

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

#### Note

Explanation for the sample:

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

## 题意

一共$m$个房间，小A$(暂且叫他小A)$每个月都要将房间的灯换成节能灯，但是小A换灯的时候有个习惯，必须要能够一次性将一个房间里的灯全部换掉才会去换掉这个房间的灯，否则就跳过这个房间去下一个房间重复这个步骤

每个月小A都会去买$m$个灯，然后一直换下去

现在每次询问都要输出两个值，当前已经换掉的房间与手中剩下的灯数

## 思路

直接暴力肯定会超时

直接套用线段树模板来维护区间最小值,每次找到最左端满足条件的房间然后将该房间的灯全部换掉查找的时候可以直接二分找到最左端满足条件的房间

每次换掉一个房间以后该房间的灯的数量加$1e5+10$ ，因为正常情况下每个房间的灯的数量不会超过$1e4$，所以当所有房间的灯都超过$1e5+10$之后，也就代表了所有房间已经全部被换成了节能灯

二分查找的过程还可以优化一下，但是不优化也不会超时，懒得改了

线段树模板:线段树模板(含区间最大(小)值)

## 代码

1 | /* |