弹幕

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        List<List<Integer>> list = new ArrayList<>();
        int big = 0;
        for (int i = 0;i<N;i++){
            String temp = sc.nextLine();
            String[] tempString = temp.split(" ");
            int first = Integer.parseInt(tempString[0]);
            int second = Integer.parseInt(tempString[1]);
            List<Integer> tempList = new ArrayList<>();
            tempList.add(first);
            tempList.add(second);
            if (second>big)big=second;
            list.add(tempList);
        }
        Map<Integer,Integer> map = new HashMap<>();
        for (List<Integer> tempList:list){
            int first = tempList.get(0);
            int second = tempList.get(1);
            for (int i = first;i<second;i++){
                if(map.containsKey(i)){
                    map.put(i,map.get(i)+1);
                }else {
                    map.put(i,1);
                }
            }
        }
        int max = 0;
        for(int val:map.values()){
            if (val>max)max=val;
        }
        int maxKey = 0;
        int minKey = 100;
        for (int val:map.keySet()){
            if (val>maxKey)maxKey=val;
            if (val<minKey)minKey=val;
        }
        for (int i=minKey;i<=maxKey;i++){
            if (map.get(i)==max){
                System.out.println(i+" "+(i+1));
            }
        }

    }

}

 

弹幕

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-11-12
  • 2021-11-08
  • 2021-10-16
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-09
  • 2021-07-21
  • 2021-06-06
  • 2021-10-24
  • 2021-10-25
  • 2021-12-09
相关资源
相似解决方案