#P16816. [蓝桥杯 2026 国 Python B] 贴纸册交换

[蓝桥杯 2026 国 Python B] 贴纸册交换

Problem Description

Xiao Lan is collecting a sticker album. There are NN types of stickers, numbered 1,2,…,N1, 2, \dots, N. He will receive MM stickers in order, where the ii-th sticker has number AiA_i.

When processing a sticker:

  • If Xiao Lan has not collected the sticker numbered AiA_i yet, he pastes this sticker into the album.
  • If Xiao Lan has already collected the sticker numbered AiA_i, this duplicate sticker becomes 11 exchange coupon.

Whenever the number of exchange coupons reaches KK, Xiao Lan must immediately spend KK exchange coupons to obtain the currently smallest-numbered sticker that has not been collected yet, and paste it into the album.

If Xiao Lan has already collected all NN types of stickers, then the stickers received afterward will no longer change the number of collected sticker types.

Please compute how many types of stickers Xiao Lan has collected in total after processing all MM stickers.

Input Format

The first line contains three integers N,M,KN, M, K, representing the number of sticker types, the number of stickers received, and the number of exchange coupons needed for each exchange.

The second line contains MM integers A1,A2,…,AMA_1, A_2, \dots, A_M, representing the sticker numbers Xiao Lan receives in order.

Output Format

Output one line containing one integer, representing the number of sticker types Xiao Lan has collected after processing all stickers.

6 10 3
2 4 2 2 5 4 1 3 3 6
6
5 7 2
4 4 2 4 2 5 5
5

Hint

Sample Explanation 1

The first two stickers are numbered 2,42, 4, and both can be pasted directly into the album. The 33-rd and 44-th stickers are both numbered 22, which are duplicates, so Xiao Lan gets 22 exchange coupons.

The 55-th sticker is numbered 55 and is pasted directly into the album. The 66-th sticker is numbered 44, which gives 11 more exchange coupon. Now there are 33 exchange coupons in total, so he must exchange immediately. The smallest number not yet collected is currently 11, so he obtains the sticker numbered 11.

He then continues processing the remaining stickers, and finally can collect all stickers numbered 11 to 66. The answer is 66.

Sample Explanation 2

The 22-nd and 44-th stickers are both duplicates of the already collected sticker numbered 44. After processing the 44-th sticker, there are 22 exchange coupons, so he must exchange for the current smallest missing sticker 11.

Later, duplicate stickers numbered 22 and 55 produce 22 more exchange coupons, and in the end he exchanges to obtain the sticker numbered 33. After processing everything, 1,2,3,4,51,2,3,4,5 have all been collected, so the answer is 55.

Constraints and Notes for Test Cases

For 30%30\% of the test cases, N,M≤200N, M \le 200.

For 60%60\% of the test cases, N,M≤5000N, M \le 5000.

For all test cases, 1≤N,M,K≤2×1051 \le N, M, K \le 2 \times 10^5, and 1≤Ai≤N1 \le A_i \le N.

Translated by ChatGPT 5