Editorial for EGOI '22 P5 - Data Centers
Submitting an official solution before solving the problem yourself is a bannable offence.
prepared for EGOI 2022 by Cheng Zhong
Subtask 1
Sorting the available machines in each of the  data centers and output the result directly,
as there's no service to be launched.
Time complexity:  or 
Subtask 2 & 3
Simulate the process. Using an array or vector to store the number of machines in each
data centers. Using some  (subtask 2) or 
 (subtask 3) sorting algorithm
to sort the data centers in descending order before launching each service, and deduct 
machines in each of the top 
 data centers.
Time complexity:  or 
Subtask 4
Instead of using quick sort or other comparison based sorting algorithms, using counting
sort as there are at most  machines in each data centers.
Time complexity: 
Subtask 5
As there's only  data center being affected after each service is launched, we could move
it to a proper position in 
 time and keep the array still in descending order.
Time complexity: 
Alternatively, instead of using an array or vector to store the number of machines, using a
priority queue. As  is always 
, while launching each service, we only need to visit and
change the root, so we only need 
 time to deal with each service.
Time complexity: 
Subtask 6
After launching each service, the data centers can be divided into two parts: one just
deducted  machines each, another remains untouched. Each part remains its
descending order. Therefore, we can merge these two parts like that in merge sort, and it
only takes 
 time to deal with each new service.
Time complexity: 
Motivation of providing this problem
Sorting algorithms has great importance and is introduced in the very first chapters in
Introduction to Algorithms and many other books. However, some students only learn that
the best time complexity for comparison sort is , and the 
sort in C++ library
provides such functionality. They don't really understand what's behind all these sorting
algorithms. This task tries to help the students thinking about the stories behind the basic
sorting algorithms, and how to take advantage of each of them.
Comments