forked from thevanshjain/DAA
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcar_fueling.java
More file actions
41 lines (41 loc) · 1.05 KB
/
Copy pathcar_fueling.java
File metadata and controls
41 lines (41 loc) · 1.05 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
import java.io.*;
import java.util.*;
class car_fueling
{
public static void main(String ar[])throws Exception
{
BufferedReader ab=new BufferedReader(new InputStreamReader(System.in));
int d=Integer.parseInt(ab.readLine());
int m=Integer.parseInt(ab.readLine());
int n=Integer.parseInt(ab.readLine());
String s[]=ab.readLine().split(" ");
List<Integer> a=new ArrayList<Integer>(n);
a.add(0);
int c=0,nr=0,l=0,p=0,count=0;
l=m;
for(int x=0;x<n;x++)
a.add(Integer.parseInt(s[x]));
a.add(d);
while(l<d)
{
try
{
while(a.get(c)<=l)
{
c++;
}
}
catch(Exception e){}
c=c-1;
p=a.get(c);
l=p+m;
count++;
if(count>n)
{
count=-1;
break;
}
}
System.out.println(count);
}
}