توجه: سوال‌ها لزوما به ترتیب سختی مرتب نشده‌اند و ترتیب آن‌ها (تقریبا!) اتفاقی است. استفاده از منابع از پیش آماده شده و دیکشنری‌ها در حین مسابقه مجاز است.

برای سرعت بیشتر برنامه‌ها، بجای پایتون می‌توانید با PyPy کدتان را ارسال کنید.

لینک‌های مفید برای شرکت در مسابقه:

می‌توانید سوال‌های خود را از بخش "سوال بپرسید" مطرح کنید.

Good Will Hunting (1997)


  • Memory Limit: 256MB
  • Time Limit: 1sec

The annual ICPC selection competition for students enrolled in Iran University of Science and Technology takes place tomorrow! This year, each team consists of KK 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 NN excited students, waiting in queue to register for the ICPC. The first team will consist of the first KK students in the queue, the second team the following KK students and so on... (NN will be divisible by KK).

Dr. Parisina has estimated the skill of each player with an integer. She would like to have the KK strongest players in the first team, the following KK 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.

Input🔗

The first line of input contains the integers NN and KK The second line contains NN space-separated integers viv_i - the number denotes the skill of the ii-th player standing in the queue. Skill levels are from the most strong to the least strong; it means skill level 11 is the strongest possible.

The integer NN will be divisible by KK, and all contestants are going to have distinct levels of skill.

1KN50001 \le K \le N \le 5000 1vi1091 \le v_i \le 10^9

Output🔗

The first and only line of output must contain the minimal required number of minutes.

Sample Input 1🔗

4 1
9 12 5 13
Plain text

Sample Output 1🔗

1
Plain text

Sample Input 2🔗

6 3
7 9 8 3 6 5
Plain text

Sample Output 2🔗

3
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.