Huawei OD Computer Test Real Questions - Optimal Task Scheduling - 2023 OD Unified Examination (Paper B)

Topic description:

Given an array of positive integers representing a list of tasks to be executed by the system, each element of the array represents a task, and the value of the element represents the type of the task. Please calculate the minimum time required to perform all tasks. The task execution rules are as follows:

1. Tasks can be executed in any order, and the execution time of each task is 1 time unit.

2. There must be a cooling time of N units between two tasks of the same type. For example: when N is 2, a task of type 3 is executed at time K, then K+1 and K+2 cannot Perform type 3 tasks.

3. The system can execute a task or wait state in any unit of time.

Note: The maximum length of the array is 1000, and the maximum value of the array is 1000.

Enter description:

The first line records an array separated by half-width commas. The length of the array does not exceed 1000, and the value of the array element does not exceed 1000.

The second line records the task cooling time, N is a positive integer, N<=100.

Output description:

The output is the minimum time required to complete all tasks.

Additional instructions:

 close

Example 1

enter:

2,2,2,3
2

Output:

7

illustrate:

Time 1: Perform type 2 tasks.

Time 2: Perform type 3 tasks (because the cooling time is 2, type 2 tasks cannot be performed at time 2).

Time 3: System waits (still on type 2 cooldown).

Time 4: Execute type 2 tasks.

Time 5: The system waits.

Time 6: The system waits.

time

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/133219235