-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay51.java
More file actions
54 lines (41 loc) · 1.33 KB
/
Day51.java
File metadata and controls
54 lines (41 loc) · 1.33 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.*;
public class Day51 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int m = scanner.nextInt();
int[] time = new int[m];
for (int i = 0; i < m; i++) {
time[i] = scanner.nextInt();
}
int low = 0;
int high = (int) Math.pow(10, 9);
while (low < high) {
int mid = low + (high - low) / 2;
if (isPossible(time, n, mid)) {
high = mid;
} else {
low = mid + 1;
}
}
System.out.println(low);
}
}
private static boolean isPossible(int[] time, int n, int maxTime) {
int days = 1;
int currentWorkload = 0;
for (int t : time) {
if (t > maxTime) {
return false;
}
if (currentWorkload + t > maxTime) {
days++;
currentWorkload = 0;
}
currentWorkload += t;
}
return days <= n;
}
}