백준 1449 java
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;
public class bj1449 {
static Scanner scanner = new Scanner(System.in);
public static Vector<Integer> inputData(int N)
{
int i, num;
Vector<Integer> data = new Vector<>();
for(i = 0; i < N; i++)
{
num = scanner.nextInt();
data.add(num);
}
Collections.sort(data);
return data;
}
public static void findAnswer(Vector<Integer> pipe, int N, int L)
{
int i;
int min = 0;
int current;
int tape = 0;
for(i = 0; i < pipe.size(); i++)
{
current = pipe.get(i);
if(current > tape)
{
tape = current + L - 1;
min++;
}
}
System.out.println(min);
}
public static void main(String[] args) {
int N, L;
Vector<Integer> pipe;
N = scanner.nextInt();
L = scanner.nextInt();
pipe = inputData(N);
findAnswer(pipe, N, L);
scanner.close();
}
}