luogu#P2418. yyy loves OI IV

yyy loves OI IV

Background

In the 2015 cohort of a certain school, there are two OI top students, yyy and c01.

Problem Description

There are NN other students in the school besides them, and each student idolizes one of them. Now the teacher needs to assign them to dorm rooms. However, here is the issue:

For any dorm room, either everyone in it idolizes the same person, or the absolute difference between the numbers of students who idolize yyy and c01 in that room is at most MM. Otherwise, they will start a fight.

To make things easier, the teacher makes the NN students stand in a line. Only people who stand consecutively can be placed into the same dorm room.

Assume each dorm room can hold arbitrarily many people. What is the minimum number of dorm rooms needed?

Input Format

The first line contains two positive integers NN and MM.

Lines 2,3,,N+12, 3, \cdots, N+1 each contain one integer, 11 or 22. The number on line ii indicates, from left to right, the (i1)(i-1)-th person’s choice: 11 means yyy, and 22 means c01.

Output Format

One line with a single integer, the minimum number of dorm rooms needed.

5 1
1
1
2
2
1
1

Hint

Test point ID Range of NN Range of MM
131 \sim 3 2500\le 2500 10\le 10
454 \sim 5 5×105\le 5\times 10 ^ 5
6106 \sim 10 2000\le 2000

Translated by ChatGPT 5