Editorial for COCI '14 Contest 6 #1 Paprika


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

We need to simulate the procedure described in the task. Therefore, we first simulate the swap of ID cards between the first and the second pepper, then between the second and the third, and so on until we reach the end.

When we've done all the swaps, we need to count all the peppers that are going to be filled and have an ID card with a number smaller than or equal to X, or all peppers that want to be served fresh and have an ID card with a number strictly larger than X.

The time complexity of this algorithm is \mathcal O(N).


Comments

There are no comments at the moment.