Carnival Tickets
문제
Ringo is at a carnival in Singapore. He has some prize tickets in his bag, which he would like to use at the prize game stall. Each ticket comes in one of colours and has a non-negative integer printed on it. The integers printed on different tickets might be the same. Due to a quirk in the carnival rules, is guaranteed to be even.
Ringo has tickets of each colour in his bag, that is a total of tickets. The ticket of the colour has the integer printed on it ( and ).
The prize game is played in rounds, numbered from to . Each round is played in the following order:
- From his bag, Ringo selects a set of tickets, one ticket from each colour. He then gives the set to the game master.
- The game master notes down the integers printed on the tickets of the set. The order of these integers is not important.
- The game master pulls out a special card from a lucky draw box and notes down the integer printed on that card.
- The game master calculates the absolute differences between and for each from to . Let's be the sum of these absolute differences.
- For this round, the game master gives Ringo a prize with a value equal to .
- The tickets in the set are discarded and cannot be used in future rounds.
The remaining tickets in Ringo's bag after rounds of the game are discarded.
By watching closely, Ringo realized that the prize game is rigged! There is actually a printer inside the lucky draw box. In each round, the game master finds an integer that minimizes the value of the prize of that round. The value chosen by the game master is printed on the special card for that round.
Having all this information, Ringo would like to allocate tickets to the rounds of the game. That is, he wants to select the ticket set to use in each round in order to maximize the total value of the prizes.