풀이)
그리디 방식으로 풀어야 한다. 최소한의 테이프를 사용해 물이 새는 것을 막아야 하는데, 범위가 작아 그리디로 배열 정렬을 하며 하나하나 해볼 수 있다.
내 코드)
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] t = br.readLine().split(" ");
int N = Integer.parseInt(t[0]);
int L = Integer.parseInt(t[1]);
int pos[] = new int[1001];
int tape=0;
String[] input = br.readLine().split(" ");
for(int i=0; i<N; i++) {
pos[Integer.parseInt(input[i])] = 1;
}
for(int i=1;i<=1000;i++) {
if(pos[i]!= 0) {
i+=L-1;
tape++;
}
}
System.out.println(tape);
}
}