-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueneeded.java
More file actions
36 lines (33 loc) · 993 Bytes
/
queueneeded.java
File metadata and controls
36 lines (33 loc) · 993 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
import java.util.Scanner;
public class queueneeded {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int No_of_Groups = sc.nextInt();
int capacity = sc.nextInt();
int[] group_size = new int[No_of_Groups];
for (int i = 0; i < No_of_Groups; i++) {
group_size[i] = sc.nextInt();
}
int No_of_Bus = 0;
for (int i = 0; i < No_of_Groups; i++) {
int temp = 0;
if (group_size[i] == capacity) {
No_of_Bus++;
} else {
while (temp < capacity) {
temp += group_size[i];
i++;
}
if (temp == capacity) {
No_of_Bus++;
i--;
} else {
No_of_Bus++;
i -= 2;
}
}
}
System.out.println(No_of_Bus);
sc.close();
}
}