#P3419. [POI 2005] SAM-Toy Cars

[POI 2005] SAM-Toy Cars

Description

Jasio is a three-year-old boy who loves to play with toy cars. He has nn toy cars stored on a shelf.

Jasio cannot reach the toy cars on the shelf, but he can reach the ones on the floor. Jasio’s mother helps by moving toy cars from the shelf to the floor.

The floor can hold at most kk toy cars.

When there are already kk toy cars on the floor, Jasio’s mother will first take one toy car from the floor back to the shelf, and then bring the toy car that Jasio wants.

Now Jasio wants to play with pp toy cars in order. Determine the minimum number of times his mother needs to take a toy car down. (Only count taking down from the shelf; do not count putting back.)

Input Format

The first line contains three integers nn, kk and pp.

The next pp lines each contain exactly one integer aia_i, indicating the ID of the toy car Jasio wants.

Output Format

Output a single integer, the minimum number of times Jasio’s mother needs to take a toy car down.

3 2 7
1
2
3
1
3
1
2
4

Hint

Constraints: For 100%100\% of the testdata: 1kn1051 \le k \le n \le 10^5, 1p5×1051 \le p \le 5 \times 10^5, 1ain1 \le a_i \le n.

Translated by ChatGPT 5