#P1564. 膜拜
膜拜
Description
There are many top students… of course… each student has someone they sincerely admire.
At a certain school there are two top students, A and B. The newly enrolled students have already heard of their legends, so each student already sincerely worships one of them. Now the teacher needs to assign them to computer labs. For each lab, either everyone in that lab worships the same top student, or the absolute difference between the counts of the two worshippers does not exceed .
The students stand in a line, and the teacher will only assign a contiguous segment of students to the same lab. The teacher wants to know the minimum number of labs needed.
Input Format
The first line contains two integers and .
Lines through each contain an integer, either or . The integer on line indicates whom the -th student worships: means A, means B.
Output Format
Output a single integer, the minimum number of labs required.
5 1
2
2
1
2
2
2
Hint
Constraints
- For of the testdata, it is guaranteed that , .
- For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号