Sensor Blocking


Sensor Blocking

Problem Statement

As usual, Seth and Andy have stayed at uni until 3am the night before their exam.

Instead of studying for their exam, they are studying the motion sensor layout of the room in order to cover the sensors with sheets of foil, so that they can continue their degeneracy with the lights off and unable to automatically turn back on.

They model the room as an array AA, with elements of AA corresponding to segments of the room. Each segment is either empty, or contains a single motion sensor with positive integer strength. Through countless hours of experimentation, Andy and Seth found that a sensor with strength xx requires at least xx overlapping sheets of foil in the sensor's segment to avoid detecting motion.

Conveniently, MAPS has a stash of sheets of foil, with each sheet capable of covering exactly kk consecutive segments. The supply isn't unlimited, however, so Andy and Seth have posed a conundrum: what is the minimum number of sheets required to fully cover every motion sensor?

Input

The first line contains two integers, nn and kk, where nn is the size of the room, and kk is the size of each sheet of foil. The second line contains nn integers a1,a2,…,ana_1, a_2, … ,a_n, where aia_i is 00 if there is no sensor in segment ii, or a positive integer corresponding to the strength of the sensor.

Output

The output consists of a single integer, the minimum number of sheets of foil required to block every sensor in the room.

Constraints

For test set 1:

  • 1≤n≤1031 \leq n \leq 10^{3}
  • 1≤k≤1031 \leq k \leq 10^{3}
  • 1≤ai≤1091 \leq a_i \leq 10^{9}

For test set 2:

  • 1≤n≤1051 \leq n \leq 10^{5}
  • 1≤k≤1051 \leq k \leq 10^{5}
  • 1≤ai≤1091 \leq a_i \leq 10^{9}

Sample Test Case

Example 1
Input 1
6 2
0 2 1 1 3 1
Output 1
5
Explanation

A possible solution, with lines of # marking a sheet of foil:

Code 1
0 2 1 1 3 1
# #
  # #
        # #
      # #
      # #

It can be shown that no configuration with fewer sheets can cover every sensor.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.