classSolution{public:intminProcessingTime(vector<int>&processorTime,vector<int>&tasks){intans=0;ranges::sort(processorTime);ranges::sort(tasks,greater<>());// It's optimal to run each 4 longer tasks with a smaller processor time.// Therefore, for each processor, take the maximum of the sum of the// processor time and the largest assigned tasks[i].for(inti=0;i<processorTime.size();++i)ans=max(ans,processorTime[i]+tasks[i*4]);returnans;}};
1 2 3 4 5 6 7 8 9101112131415
classSolution{publicintminProcessingTime(List<Integer>processorTime,List<Integer>tasks){intans=0;Collections.sort(processorTime);Collections.sort(tasks,Collections.reverseOrder());// It's optimal to run each 4 longer tasks with a smaller processor time.// Therefore, for each processor, take the maximum of the sum of the// processor time and the largest assigned tasks[i].for(inti=0;i<processorTime.size();++i)ans=Math.max(ans,processorTime.get(i)+tasks.get(i*4));returnans;}}