diff --git "a/Ho/202508/6 \352\260\234\353\230\245\353\262\214\353\240\210.md" "b/Ho/202508/6 \352\260\234\353\230\245\353\262\214\353\240\210.md" new file mode 100644 index 0000000..a8b77ca --- /dev/null +++ "b/Ho/202508/6 \352\260\234\353\230\245\353\262\214\353\240\210.md" @@ -0,0 +1,76 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + static int N,H; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + H = Integer.parseInt(st.nextToken()); + + int[] up; + int[] down; + + up = new int[N/2]; + down = new int[N/2]; + + for (int i = 0; i < N; i++) { + if(i % 2 == 0) { + down[i/2] = Integer.parseInt(br.readLine()); + } + else { + up[i/2] = Integer.parseInt(br.readLine()); + } + } + + Arrays.sort(up); + Arrays.sort(down); + + // 최소 개수랑, 해당 구간을 구해야한다. + int min = N; + int cnt = 0; + + for(int i = 1; i <= H; i++) { + int upConflict = binarySearch(down, i); + int downConflict = binarySearch(up, H - i + 1); + + int sum = upConflict + downConflict; + if(min == sum) { + cnt++; + continue; + } + if(min > sum) { + min = sum; + cnt = 1; + } + } + + System.out.println(min + " " + cnt); + + } + + private static int binarySearch(int[] arr, int target) { + int l = 0; + int r = (N/2); + + while(l < r) { + int mid = (l + r) / 2; + int num = arr[mid]; + + if(num >= target) { + r = mid; + } else if(num < target) { + l = mid + 1; + } + } + return arr.length - r; + } +} +``` \ No newline at end of file