/** bytedance.com Inc.* Copyright (c) 2012-2022 All Rights Reserved.*/import java.util.*;/*** @author 陈奂宇* @version 1: Test.java, v 0.1 2022年08月31日 20:11 陈奂宇 Exp $$*/public class Test {public static void main(String[] args) {// 获取输入Scanner sc = new Scanner(System.in);// 苹果数量int apples = sc.nextInt();// 人数int people = sc.nextInt();// 苹果高度int[] appleNums = new int[apples];for (int i = 0; i < apples; i++) {appleNums[i] = sc.nextInt();}// 人高度int[] peopleNums = new int[people];for (int i = 0; i < people; i++) {peopleNums[i] = sc.nextInt();}// 苹果排序Arrays.sort(appleNums);// 哈希表:key是苹果高度,value是数组下标HashMap<Integer, Integer> map = new HashMap<>();// 有序链表ArrayList<Integer> list = new ArrayList<>();// 链表for (int i = 0; i < appleNums.length; i++) {map.put(appleNums[i],i);list.add(appleNums[i]);}// 开始计算for (int temp : peopleNums) {// 剪枝:链表已经小于0了if (list.isEmpty()) {break;}// 剪枝:如果大于最大值if (temp >= list.get(list.size()-1)) {list.remove(list.size()-1);continue;}// 剪枝:如果小于最小值else if (temp < list.get(0)) {continue;}// 剪枝:如果有匹配的值else if (map.containsKey(temp)) {Integer index = map.get(temp);map.remove(temp);list.remove(index);continue;}// 寻找最接近但不大于自己的值int index = list.size()-1;while (index >= 0 && list.get(index) > temp) {if (list.get(index) == temp) {list.remove(index);break;}index--;}if (index >= 0) {list.remove(index+1);}}// 返回结果System.out.println(list.size());}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。