#P6831. [IOI 2020] 嘉年华奖券
[IOI 2020] 嘉年华奖券
Description
Ringo is attending a carnival event held in Singapore. He has some tickets in his pocket, and these tickets can be used at the game booths in the carnival. Suppose there are colors of tickets. Each ticket is painted in exactly one color and has a non-negative integer printed on it. Different tickets may have the same number. According to the carnival rules, is guaranteed to be even.
Ringo has tickets of each color, so he has a total of tickets. For the -th ticket of color , the printed number is ( and ).
A ticket game consists of rounds, numbered from to . Each round works as follows:
- First, Ringo selects one ticket from each color, forming a set of tickets.
- Then, the game host writes down the numbers on the tickets in this set: . The order of these integers does not matter.
- Next, the host draws a special card from a lucky draw box, which has an integer printed on it.
- For each ticket number in the set, the host computes the absolute value of the difference between and . Let be the sum of these absolute differences.
- The value is the reward Ringo gets in this round.
- After the round ends, all tickets in the set are discarded and will not be used in future rounds.
After the rounds are finished, Ringo discards all remaining tickets in his pocket.
After careful observation, Ringo discovers that the ticket game is rigged. In fact, there is a printer inside the lucky draw box. In each round, the host first finds an integer that minimizes the reward of the current round, and then prints that number on the special card that he draws.
Knowing this, Ringo wants to design the ticket allocation plan for each round so that the total reward over the rounds is maximized.
Implementation details
You need to implement the following function:
long long find_maximum(int k,std::vector<std::vector<int>> x)
- : the number of rounds.
- : an array recording the numbers on the tickets. For each color, the tickets are sorted in non-decreasing order of the numbers above.
- This function will be called only once.
- This function should call the function
allocate_ticketsexactly once (see below) to describe the allocation plan of tickets across the rounds, where each round corresponds to one set of tickets. The allocation plan should maximize the total reward. - This function must return the maximum possible total reward.
The function allocate_tickets is defined as follows:
void allocate_tickets(std::vector<std::vector<int>> s)
- : an array. If the -th ticket of color is assigned to round , then should be ; if it is not used, it should be .
- For each , in , each value must appear exactly once, and all other elements should be .
- If there are multiple optimal allocation plans that achieve the maximum reward, you may output any one of them.
Hint
Sample explanation
Example 1
Consider the following function call:
find_maximum(2, [[0, 2, 5],[1, 1, 3]])
This means:
- The game is played for rounds.
- The integers on the tickets of color are and .
- The integers on the tickets of color are and .
One optimal allocation plan is:
- In round , Ringo chooses the -th ticket of color (printed with ) and the -nd ticket of color (printed with ). The minimum reward in this round is . For example, the host can choose : .
- In round , Ringo chooses the -nd ticket of color (printed with ) and the -st ticket of color (printed with ). The minimum reward in this round is . For example, the host can choose : .
- Therefore, the sum of rewards over the two rounds is .
To output this allocation plan, find_maximum should call allocate_tickets as follows:
allocate_tickets([[0, -1, 1], [-1, 1, 0]])
Finally, find_maximum should return .
Example 2
Consider the following function call:
find_maximum(1, [[5, 9], [1, 4], [3, 6], [2, 7]])
This means:
- The game is played for only one round.
- The numbers on tickets of color are and .
- The numbers on tickets of color are and .
- The numbers on tickets of color are and .
- The numbers on tickets of color are and .
One optimal allocation plan is:
- In round , Ringo chooses the -st ticket of color (printed with ), the -th ticket of color (printed with ), the -th ticket of color (printed with ), and the -st ticket of color (printed with ). The minimum reward in this round is . For example, the host can choose : .
To output this allocation plan, find_maximum should call allocate_tickets as follows:
allocate_tickets([[-1, 0], [0, -1], [0, -1], [-1, 0]])
Finally, find_maximum should return .
Constraints
- and is even.
- .
- (for all and ).
- (for all and ).
Subtasks
- (11 points) .
- (16 points) .
- (14 points) (for all and ).
- (14 points) .
- (12 points) .
- (23 points) .
- (10 points) No additional constraints.
Sample grader program
The sample grader reads the input in the following format:
Line :
Line ():
The sample grader prints your output in the following format:
Line : the return value of find_maximum
Line ():
Translated by ChatGPT 5
京公网安备 11011102002149号