- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
The annual ICPC selection competition for students enrolled in Iran University of Science and Technology takes place tomorrow! This year, each team consists of $K$ students (Recent years there has been a lot of changes in the regulations, so this makes the change of the number of team members quite expectable!).
There are $N$ excited students, waiting in queue to register for the ICPC. The first team will consist of the first $K$ students in the queue, the second team the following $K$ students and so on... ($N$ will be divisible by $K$).
Dr. Parisina has estimated the skill of each player with an integer. She would like to have the $K$ strongest players in the first team, the following $K$ strongest in the second team, and so on. So Dr. Parisina decided to shift the students standing in the queue so that she achieves her goal. The way she shifts them is that she tells a student to step out of the queue and go back in the queue before another student or to go to the front of the queue (So she can move anyone to anywhere). It takes her one minute to do this. Her class will be started soon, so Dr. Parisina needs to achieve her goal as soon as possible. Help Dr. Parisina determine the minimal number of minutes necessary for her to achieve her goal.
ورودی
The first line of input contains the integers $N$ and $K$ The second line contains $N$ space-separated integers $v_i$ - the number denotes the skill of the $i$-th player standing in the queue. Skill levels are from the most strong to the least strong; it means skill level $1$ is the strongest possible.
The integer $N$ will be divisible by $K$, and all contestants are going to have distinct levels of skill.
$$1 \le K \le N \le 5000$$ $$1 \le v_i \le 10^9$$
خروجی
The first and only line of output must contain the minimal required number of minutes.
مثال
ورودی نمونه ۱
4 1
9 12 5 13
خروجی نمونه ۱
1
ورودی نمونه ۲
6 3
7 9 8 3 6 5
خروجی نمونه ۲
3
ارسال پاسخ برای این سؤال