CF BUDDY
← Problems·

1070D · Garbage Disposal

1300 · greedy

Problem: Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.

For each of next nn days Vasya knows aia_i — number of units of garbage he will produce on the ii-th day. Each unit of garbage must be disposed of either on the day it was produced or on the next day. Vasya disposes of garbage by putting it inside a bag and dropping the bag into a garbage container. Each bag can contain up to kk units of garbage. It is allowed to compose and drop multiple bags into a garbage container in a single day.

Being economical, Vasya wants to use as few bags as possible. You are to compute the minimum number of bags Vasya needs to dispose of all of his garbage for the given nn days. No garbage should be left after the nn-th day.

Input Format: The first line of the input contains two integers nn and kk (1n2105,1k1091 \le n \le 2\cdot10^5, 1 \le k \le 10^9) — number of days to consider and bag's capacity. The second line contains nn space separated integers aia_i (0ai1090 \le a_i \le 10^9) — the number of units of garbage produced on the ii-th day.

Output Format: Output a single integer — the minimum number of bags Vasya needs to dispose of all garbage. Each unit of garbage should be disposed on the day it was produced or on the next day. No garbage can be left after the nn-th day. In a day it is allowed to compose and drop multiple bags.

Sample Cases

Case 1

Input

3 2
3 2 1

Output

3

Case 2

Input

5 1
1000000000 1000000000 1000000000 1000000000 1000000000

Output

5000000000

Case 3

Input

3 2
1 0 1

Output

2

Case 4

Input

4 4
2 8 4 1

Output

4

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback