728x90
반응형
https://www.acmicpc.net/problem/1449
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int L = Integer.parseInt(st.nextToken()); int[] arr = new int[N]; int result = 0; st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { arr[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(arr); for (int i = 0; i < N; i++) { int cnt = 0; result+=1; for (int j = i + 1; j < N; j++) { if (arr[j] - arr[i] < L) { cnt++; } } i += cnt; } System.out.println(result); } } | cs |
728x90
'Algorithm > BOJ' 카테고리의 다른 글
백준) 2812_크게 만들기 (0) | 2023.06.07 |
---|---|
백준) 3055_탈출 (2) | 2023.05.19 |
백준) 7569_토마토2 (2) | 2023.05.17 |
백준) 7576_토마토 (1) | 2023.05.17 |
백준) 2133_타일 채우기 (0) | 2023.05.16 |