File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ String [] firstLine = br. readLine(). split(" " );
9+ int N = Integer . parseInt(firstLine[0 ]);
10+ int M = Integer . parseInt(firstLine[1 ]);
11+
12+ String [] secondLine = br. readLine(). split(" " );
13+ Integer [] times = new Integer [N ];
14+ for (int i = 0 ; i < N ; i++ ) {
15+ times[i] = Integer . parseInt(secondLine[i]);
16+ }
17+
18+ Arrays . sort(times, (a, b) - > b - a);
19+
20+ PriorityQueue<Long > pq = new PriorityQueue<> ();
21+ for (int i = 0 ; i < M ; i++ ) {
22+ pq. offer(0L );
23+ }
24+
25+ for (int time : times) {
26+ long minTime = pq. poll();
27+ pq. offer(minTime + time);
28+ }
29+
30+ long result = 0 ;
31+ while (! pq. isEmpty()) {
32+ result = Math . max(result, pq. poll());
33+ }
34+
35+ System . out. println(result);
36+ }
37+ }
38+ ```
You can’t perform that action at this time.
0 commit comments