-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram40.java
More file actions
43 lines (32 loc) · 983 Bytes
/
Program40.java
File metadata and controls
43 lines (32 loc) · 983 Bytes
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
// Program 40
// Week 2 - Day 1
// The first line contain two integers n and m(1<=n, m <=100).
// output format: Print a single string - the number of buses needed to transport all n group to the jeju Island contaryside
// Input: 4 4
// 3 3 3 3
// output: 4
import java.util.Scanner;
public class Program40 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] groups = new int[n];
for (int i = 0; i < n; i++) {
groups[i] = sc.nextInt();
}
int busCount = 0;
int currentBusLoad = 0;
for (int i = 0; i < n; i++) {
if (currentBusLoad + groups[i] > m) {
busCount++;
currentBusLoad = 0;
}
currentBusLoad += groups[i];
}
if (currentBusLoad > 0) {
busCount++;
}
System.out.println(busCount);
}
}