Under construction

Still being built. Things may change

Melons

Interview

Time limit1sMemory limit1024 MB

Summary
For each start index x, count the boxes needed to pack melons x through N in order under limit L, and report the weight of the last box.
Level

Medium6 of 10

Topics
Greedy, Prefix sum, Two pointers, Dynamic programming
Solved
No attempts yet

Problem

In EGOI Farm, employees receive and ship melons. This morning, NN melons arrived. The melons are numbered from 1 to NN, and the weight of melon ii (1≤i≤N1 \le i \le N) is AiA_i.

Rie works at EGOI Farm, packing melons into boxes. An integer xx (1≤x≤N1 \le x \le N) is decided. Then she receives melons x,x+1,…,Nx, x+1, \dots, N in this order. She packs them by repeating the following process.

  • Rie takes an empty box and keeps putting melons into it. If the total weight in the box would exceed LL after adding the next melon, she does not put that melon in. She then ships the box. In this case, the next melon goes into a new box.

After melon NN is put into a box, she ships that box, and the job ends.

Rie wants to prepare for every possible value of xx. Given the melon weights and the maximum box weight LL, write a program that computes, for every xx, the number of boxes she ships and the total weight of melons in the last box.

Input

The first line contains NN and LL. Each of the next NN lines contains one value: A1,A2,…,ANA_1, A_2, \dots, A_N.

N L
A_1
A_2
\vdots
A_N

Output

Print NN lines. The ii-th line contains, for x=ix = i, the number of shipped boxes and the total weight of melons in the last box, separated by a space.

Constraints

  • 1≤N≤200 0001 \le N \le 200\,000
  • 1≤L≤1 000 000 0001 \le L \le 1\,000\,000\,000 (=109= 10^9)
  • 1≤Ai≤L1 \le A_i \le L (1≤i≤N1 \le i \le N)

Examples3

  1. Example 1

    Input
    7 100
    20
    80
    50
    40
    20
    80
    10
    
    Expected output
    4 10
    4 10
    3 10
    2 90
    2 10
    1 90
    1 10
    
  2. Example 2

    Input
    6 160
    63
    63
    63
    63
    63
    63
    
    Expected output
    3 126
    3 63
    2 126
    2 63
    1 126
    1 63
    
  3. Example 3

    Input
    5 20
    7
    10
    4
    6
    8
    
    Expected output
    2 18
    2 8
    1 18
    1 14
    1 8