-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC435A.java
More file actions
36 lines (27 loc) · 773 Bytes
/
Copy pathC435A.java
File metadata and controls
36 lines (27 loc) · 773 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.io.BufferedReader;
import java.io.InputStreamReader;
public class C435A {
/***/
public static void main(String[] args) {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
try{
String[] s=reader.readLine().split(" ", 2);
int n=Integer.valueOf(s[0].trim()).intValue();
int m=Integer.valueOf(s[1].trim()).intValue();
s=reader.readLine().split(" ", n);
int[] g=new int[n];
for(int i=0;i!=n;i++)
g[i]=Integer.valueOf(s[i].trim()).intValue();
int bus=1;
int currentCharge=0;
for(int i=0;i!=n;i++){
if((currentCharge+g[i])>m){
currentCharge=g[i];
bus++;
}else currentCharge+=g[i];
}
System.out.println(bus);
reader.close();
}catch(Exception e){}
}
}