Line Sweep
\nclass Solution {\n    public List<Integer> busiestServers(int k, int[] arrival, int[] load) {\n        int[] counts = new int[k];\n        int[] eventToServer
```\nclass Solution {\n    public List<Integer> busiestServers(int k, int[] arrival, int[] load) {\n        int[] counts = new int[k];\n        int[] eventToServer = new int[arrival.length];\n        TreeSet<Integer> freeServers = new TreeSet<>();\n        for(int i = 0; i<k; i++){\n            freeServers.add(i);\n        }\n        \n        Set<Integer> eventsDropped = new HashSet<>();\n        \n        int[][] events = new int[arrival.length*2][];//[time, eventID, start/end:0/1]\n        \n        for(int i = 0; i<arrival.length; i++){\n            int start = arrival[i];\n            int end = start + load[i];\n            events[i] = new int[]{start, i, 0};\n            events[i+arrival.length] = new int[]{end, i, 1};\n        }\n        \n        Arrays.sort(events, (i,j)->{\n            if(i[0]-j[0]!=0){\n                return i[0]-j[0];\n            }\n            if(i[2]==0 && j[2]==1){\n                return 1;\n            }else if(i[2]==1 && j[2]==0){\n                return -1;\n            }\n            return i[1]-j[1];\n        });\n        \n        for(int i = 0; i<(arrival.length*2); i++){\n            int[] event = events[i];\n            int serverID = event[1]%k;\n            \n            if(event[2]==0){\n                if(freeServers.size()>0){\n                    Integer actualServerID = freeServers.ceiling(serverID);\n                    if(actualServerID==null){\n                        serverID=-1;\n                        actualServerID = freeServers.ceiling(serverID);\n                    }\n                    counts[actualServerID]++;\n                    freeServers.remove(actualServerID);\n                    eventToServer[event[1]] = actualServerID;\n                }else{\n                    eventsDropped.add(event[1]);\n                }\n            }else{\n                if(!eventsDropped.contains(event[1])){\n                    freeServers.add(eventToServer[event[1]]);\n                }\n            }\n        }\n        \n        \n        \n        List<Integer> result = new ArrayList<>();\n        int max = 0;\n        \n        for(int i = 0; i<k; i++){\n            if(max<counts[i]){\n                result.clear();\n                max = counts[i];\n                result.add(i);\n            }else if(max==counts[i]){\n                result.add(i);\n            }\n        }\n        \n        return result;\n    }\n}\n```
[]