15,993,109 members
1.00/5 (1 vote)
See more:
A compting cluster jas multiple processor, each with 4 cores. The number of tasks to handle is equal to the total number of cores in the custer. Each task has predicted execution time, and each processor has a speified time when it's core becomes avilable. Assuming that exactly 4 tasks are assigned to each processor and those tasks run independently (asynchonocnously) on the cores of the chosen processor, what is the earliest time that all the tasks can be processed.

Eaxmple:

n=2
processorTim=[8,9=10]
taskTime=[2,2,3,1,8,7,4,5]

One optimal solution is as follows:

Assign the tasks with the execution times 2,3,7 and 8 to processor 0 that start at time 8

Assign the tasks with the execution times 4,2,5,1 to proecessor 1 that start at time 10.

The first processor cores finish at times. (8+2), (8+3), (8+7) abd (8+8) which are 10,11,15 and 16 respectively.
The second processor cores finish at (10+4), (10+2), (10+5), and (10+1) which are 14, 12 , 15 and 11 respectively. The maximum among those finishing times is 16. This is the ealiest possible finis time.

Complete the function minTime below,

minTime has the following parammeters
int processTime[n]: each processorTime[i] denotes the time at which all 4 cores of the ith processor become available
int taskTime[4*n] each taskTime[i] denotes the execution time of the ith task

Returns int: the earliesr time at which all the tasks can be finished.

java 17

public static int minYime(List<integer> processTime, List<integer> taskTime){

//code
}

Input format for custom resring:

The first line cntains an integer, n, the nuber of processor
the ith of the next n subsequence lines contans an integer, processTime[i],
the next line conatins an integer, (4*n), the nu,ber of tasks

the ith of the next (4*n ) subsequent lines contai s an integer, taskTime[i]

sample case 0

STDIN. FUNCTION

2 -> number of processor,
n =2
10 -> processTime =[10,
20]
20
8. -> number of tasks =8
2. -> taskTime = [2,3,1,
2,5,8,4,3]
3
1
2
5
8
4
3

sample output
23

There are 2 processor that become available at time 10 and 20 and there are 8 tasks with executoon times 2,3,1,2,5,8,4 and 3. It is optimal to do the follwing:

Assign to the first processor (which becomes available at time 10) the tasks with the follwoing exectiyon times 1,4,5 and 8

Assign to the second processor (which becomes available at time 20) the tasks with the followung execution times: 2,2,3 and 3

The tasks assgned to the first processor fish at time (10+1), (10+4), (10+5) and (10+8) which are 11,14,15 and 18 respectively.

The tasks assgned to the second processor fish at time (22+2), (22+2), (22+3) and (22+3) which are 22, 22, 23 ad 23 respectively.

The maximum amongest those finishing times is 23. There is no way to copelet all the tasks earlier

test 1
inputr
2
10
20
8
2
3
1
2
5
8
4
3

ouptut from the code: 30

expected oitput 23

test 2:
1
10
4
10
10
10
10

output of the code 50:

expected 20

What I have tried:

Java
```Collections.sort(processTime);
Collections.sort(taskTime, Collections.reverseOrder());
int n = processTime.size();
int maxFinishTime = 0;
for(int i = 0; i < n; i++) {
int startTime = processTime.get(i); int finishTime = 0;
for(int j = 0; j < 4; j++) {
int taskIndex = i * 4 + j;
if (taskIndex < taskTime.size()) {
int taskFinishTime = startTime + taskTime.get(taskIndex);
if (taskFinishTime > finishTime) {
finishTime = taskFinishTime;
}
}
}
if (finishTime > maxFinishTime) {
maxFinishTime = finishTime; }
}
return maxFinishTime;```
Posted
Updated 13-Jun-24 9:50am
v2
Comments
OriginalGriff 14-Jun-24 0:09am
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Pete O'Hanlon 10 Abhinav S 5 M Imran Ansari -6
 OriginalGriff 371 Pete O'Hanlon 215 CPallini 110 Dave Kreskowiak 60 CHill60 42

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900