-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontest1283.java
More file actions
54 lines (48 loc) · 1.41 KB
/
contest1283.java
File metadata and controls
54 lines (48 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Collections;
import java.util.*;
public class contest1283 {
public static void main(String[] args){
int[] weights = {147,73,265,305,191,152,192,293,309,292,182,157,381,287,73,162,313,366,346,47};
int D = 10;
System.out.println(shipWithinDays(weights, D));
}
public static int shipWithinDays(int[] weights, int D) {
int res = 0;
int maxWeithg = 0;
int sum = 0;
List<Integer> ws = new ArrayList<>();
for(int w : weights){
maxWeithg = Math.max(w, maxWeithg);
sum += w;
ws.add(w);
}
int curSubSum = 0;
int counts = 0;
boolean exceed = false;
Collections.sort(ws);
for(int i = maxWeithg; i <= sum; i++){
System.out.println("i: " + i);
exceed = false;
counts = 0;
curSubSum = 0;
for(int j = 0; j < weights.length; j++){
int w = weights[j];
if(curSubSum + w <= i){
curSubSum += w;
}else{
curSubSum = w;
counts ++;
}
if(counts >= D){
exceed = true;
break;
}
}
System.out.println(exceed);
if(!exceed){
return i;
}
}
return res;
}
}