package com.hello;

import java.util.*;

/**
 * Hello world!
 */
public class BestHotel {
    public static void main(String[] args) {
        System.out.println("Hello Best Hotel!");
        best_hotels();
    }

    private static class Hotel {
        private long id = 0;
        private ArrayList<Integer> scoreList = new ArrayList<Integer>();
        private int totalScore = 0;

        public Hotel(long id) {
            this.id = id;
        }

        public long getId() {
            return id;
        }

        public void addScore(int score) {
            this.scoreList.add(score);
            this.totalScore += score;
        }

        public double getAverageScore() {
            if (scoreList.size() <= 0) {
                return 0;
            }
            return (double) totalScore / scoreList.size();
        }
    }

    public static class HotelComparator implements Comparator<Hotel> {
//        @Override
        public int compare(Hotel o1, Hotel o2) {
            int ret = ((Double)o2.getAverageScore()).compareTo(o1.getAverageScore());
            if (ret == 0) {
                ret = (int) (o1.getId() - o2.getId());
            }
            return ret;
        }
    }

    static void best_hotels() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        HashMap<Long, Hotel> idScoresMap = new HashMap<Long, Hotel>();
        while (n-- > 0) {
            long id = sc.nextLong();
            int score = sc.nextInt();

            Hotel scores = idScoresMap.get(id);
            if (scores == null) {
                scores = new Hotel(id);
                idScoresMap.put(id, scores);
            }

            scores.addScore(score);
        }
        sc.close();

        Hotel[] hotels = new Hotel[idScoresMap.size()];
        idScoresMap.values().toArray(hotels);
        Arrays.sort(hotels, new HotelComparator());

        for (Hotel hotel : hotels) {
            System.out.println(hotel.getId());
        }
    }
}

@@ -203,24 +203,811 @@
 s();%0A    %7D%0A%0A
+    static void best_hotels() %7B%0A        Scanner sc = new Scanner(System.in);%0A        long n = sc.nextLong();%0A%0A        HashMap%3CLong, Hotel%3E idScoresMap = new HashMap%3CLong, Hotel%3E();%0A        while (n-- %3E 0) %7B%0A            long id = sc.nextLong();%0A            int score = sc.nextInt();%0A%0A            Hotel scores = idScoresMap.get(id);%0A            if (scores == null) %7B%0A                scores = new Hotel(id);%0A                idScoresMap.put(id, scores);%0A            %7D%0A            scores.addScore(score);%0A        %7D%0A        sc.close();%0A%0A        Hotel%5B%5D hotels = new Hotel%5BidScoresMap.size()%5D;%0A        idScoresMap.values().toArray(hotels);%0A        Arrays.sort(hotels, new HotelComparator());%0A%0A        for (Hotel hotel : hotels) %7B%0A            System.out.println(hotel.getId());%0A        %7D%0A    %7D%0A%0A
     private 
@@ -1994,795 +1994,7 @@
    %7D
-%0A%0A    static void best_hotels() %7B%0A        Scanner sc = new Scanner(System.in);%0A        long n = sc.nextLong();%0A%0A        HashMap%3CLong, Hotel%3E idScoresMap = new HashMap%3CLong, Hotel%3E();%0A        while (n-- %3E 0) %7B%0A            long id = sc.nextLong();%0A            int score = sc.nextInt();%0A%0A            Hotel scores = idScoresMap.get(id);%0A            if (scores == null) %7B%0A                scores = new Hotel(id);%0A                idScoresMap.put(id, scores);%0A            %7D%0A%0A            scores.addScore(score);%0A        %7D%0A        sc.close();%0A%0A        Hotel%5B%5D hotels = new Hotel%5BidScoresMap.size()%5D;%0A        idScoresMap.values().toArray(hotels);%0A        Arrays.sort(hotels, new HotelComparator());%0A%0A        for (Hotel hotel : hotels) %7B%0A            System.out.println(hotel.getId());%0A        %7D%0A    %7D
 %0A%7D%0A

Update bestHotel