#P3694. 邦邦的大合唱站队
邦邦的大合唱站队
Description
There are idols standing in a line, coming from different bands. Each band has at least one idol.
We want to rearrange the line so that idols from the same band stand together contiguously. The way to rearrange is: let some idols leave the line (the remaining idols do not move), then let the removed idols return one by one to fill the vacated positions; they may return to any empty positions.
What is the minimum number of idols that must leave the line?
Input Format
The first line contains integers and .
Then there are lines, each containing an integer , representing the band ID of the -th idol in the line.
Output Format
Output a single integer, the answer.
12 4
1
3
2
4
2
1
2
3
1
1
3
4
7
Hint
Sample explanation:
1 3 √
3 3
2 3 √
4 4
2 4 √
1 2 √
2 2
3 2 √
1 1
1 1
3 1 √
4 1 √
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号