B. Heidi and Library (medium)time limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.InputSame as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.OutputSame as the easy version.ExamplesInput4 1001 2 2 1Output2Input4 11 2 2 1Output3Input4 21 2 3 1Output3
Input4 1001 2 2 1
Output2
['data structures', 'greedy', '*1800']