Under construction

Still being built. Things may change

Roller Coaster 2

Time limit8sMemory limit1024 MB

Summary
Given groups in a line for a coaster with capacity M, find the fewest runs after swapping at most one pair of adjacent groups.
Level

Medium5 of 10

Topics
Array, Greedy, Simulation
Solved
No attempts yet

Problem

JAG (Japan Amusement Group) is a popular amusement park that attracts many tourists. Its roller coaster is the most popular attraction.

Today the park is crowded, and many group guests are waiting in line in front of the roller coaster. As a staff member, you check the line. There are currently NN groups in the waiting line, and the ii-th group from the front has aia_i people.

The roller coaster can carry up to MM people in one run. For each run, you seat guests by the following rules, and you repeat this until the waiting line is empty.

  1. If the line is empty, or if the group at the front has more people than the number of empty seats, the coaster departs and this run ends.
  2. Otherwise, seat all people in the front group in the empty seats.
  3. Return to step 1.

You notice that the park is about to close. You consider whether swapping the order of one pair of adjacent groups can reduce the number of runs. Specifically, you may perform the following operation at most once.

Choose an integer ii with 1≤i≤N−11 \le i \le N-1, and swap the ii-th and (i+1)(i+1)-th groups in the waiting line.

If you perform the operation optimally, what is the minimum number of runs needed to empty the waiting line? No new guests join the line, and no waiting guests leave it.

Input

The first line contains integers NN and MM. NN is the number of waiting groups, with 2≤N≤2×1052 \le N \le 2 \times 10^5. MM is the maximum number of people who can ride in one run, with 1≤M≤1091 \le M \le 10^9.

The second line contains NN integers a1,a2,…,aNa_1, a_2, \ldots, a_N, with 1≤ai≤M1 \le a_i \le M.

The sum of NN over all datasets does not exceed 2×1062 \times 10^6. The input contains at most 50 datasets and ends with a line containing two zeros.

Output

For each dataset, print on one line the minimum number of runs needed when the operation is performed optimally.

Examples1

  1. Example 1

    Input
    9 5
    3 3 2 2 3 3 2 2 2
    6 20
    9 15 7 18 5 6
    0 0
    
    Expected output
    5
    4