Untitled
unknown
java
a year ago
1.6 kB
4
Indexable
Never
public class Solution { public static int findFirstLarger(int[] arr, int target) { int left = 0; int right = arr.length - 1; int resultIndex = -1; while (left <= right) { int mid = left + (right - left) / 2; if (arr[mid] > target) { resultIndex = mid; right = mid - 1; } else { left = mid + 1; } } return resultIndex; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); int[] a = new int[n]; int[] b = new int[m]; for (int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } for (int i = 0; i < m; i++) { b[i] = scanner.nextInt(); } scanner.close(); Arrays.sort(b); int cnt = 0; for (int i = 0; i < n; i++) { int idx = findFirstLarger(b, a[i]); if (m & 1 == 1) { if (idx == 0 && a[i] != b[0]) { cnt += 1; continue; } if (idx & 1 == 0 && a[i] != b[idx] && a[i] != b[idx-1]) { cnt += 1; } } else { if (idx & 1 == 1 && a[i] != b[idx] && a[i] != b[idx-1]) { cnt += 1; } } } System.out.println(cnt); } }