#P13339. [EGOI 2025] Gift Boxes
[EGOI 2025] Gift Boxes
题目描述
This year's EGOI is organized in Bonn. The organizers want to distribute at most one gift box to every team in the contest, with each team represented by a number from to . The contestants are standing in a single row. However, they are mixed up such that people from the same team might not be standing next to each other. Note that there will be at least one team with more than one person in the row. There are people in the row. Person is part of the team . The problem is: each team should only receive a maximum of one gift box. In order to ensure the process runs smoothly - and willing to leave some teams with no gift as a consequence - the organizers wish to pause the gifting process exactly once, skipping a few contestants before resuming the gift box handouts. In other words, they will skip one consecutive segment of the contestants.
It is not necessary that every team receives a gift. Nevertheless, the organizers want to maximize the number of teams that will receive their gifts while ensuring that no team ends up with two or more gifts, equivalent to minimizing the number of contestants that are skipped under this condition. Please help the organizers to decide when it is best to pause and when to continue distributing gifts such that as few contestants as possible are skipped.
输入格式
The first line of input contains two integers, and – the number of teams and the number of contestants in the row.
The second line contains integers, , where the th integer describes which team the person at position in the row belongs to. It is guaranteed that every integer between and appears at least once.
输出格式
Output two integers, and , where is the index of the first person that is skipped and is the index of the last skipped person. Note that and are indexed from to . If there is more than one solution, print any one of them.
4 5
1 3 0 2 3
1 1
3 6
1 0 2 2 1 0
0 2
4 8
0 2 0 1 2 1 3 3
2 6
3 6
1 1 2 0 1 0
0 3
4 6
0 1 2 0 3 2
2 3
5 13
3 3 3 1 2 0 3 3 2 1 4 1 0
1 9
提示
Examples
The first sample satisfies the constraints of test groups 1, 3, 5 and 6. Two different outputs are possible: corresponding to the solid blue line and corresponding to the red dotted line, as described in the picture below. Either way, all four teams receive gifts and no team receives more than one gift.
$\begin{array}{lllll} 1 & \blue 3 & 0 & 2 & \red 3 \end{array}$
The second sample satisfies the constraints of test groups 2, 3, 4, 5 and 6. Again, two different outputs are possible: and , as described in the picture below. In both cases, all three teams receive gifts.
$\begin{array}{lllll} \blue 1 & \blue 0 & \blue 2 & \red 2 & \red 1 & \red 0 \end{array}$
The third sample satisfies the constraints of test groups 3, 4, 5, 6. The optimal solution is that three teams receive a gift, as shown below. The contestants with indices 0, 1 and 7, who are in teams 0, 2 and 3, respectively, receive gifts. This is the only possible solution.
$\begin{array}{lllllll} 0 & 2 & \blue 0 & \blue 1 & \blue 2 & \blue 1 & \blue 3 & 3 \end{array}$
The fourth sample satisfies the constraints of test groups 3, 5 and 6. Again two different outputs are possible: and , as described in the picture below. In both cases, exactly two teams (team 0 and team 1) receive gifts. Team 2 does not receive a gift as doing so would require giving team 0 or 1 two gifts, which is strictly forbidden.
$\begin{array}{lllllll} \blue 1 & \blue 1 & \blue 2 & \blue 0 & 1 & 0 \end{array}$
$\begin{array}{lllllll} 1 & \red 1 & \red 2 & \red 0 & \red 1 & 0 \end{array}$
The fifth sample satisfies the constraints of test groups 3, 5 and 6. The only possible answer is , as described in the picture below. All four teams receive gifts.
$\begin{array}{lllllll} 0 & 1 & \blue 2 & \blue 0 & 3 & 2 \end{array}$
The sixth sample satisfies the constraints of test groups 3, 5 and 6. A maximum of four out of five teams can receive a gift, as shown below. The contestants with indices 0, 10, 11 and 12, who are in teams 3, 4, 1 and 0, respectively, receive gifts. This is the only possible solution.
$\begin{array}{lllllll} 3 & \blue 3 & \blue 3 & \blue 1 & \blue 2 & \blue 0 & \blue 3 & \blue 3 & \blue 2 & \blue 1 & 4 & 1 & 0 \end{array}$
Constraints and Scoring
- .
- .
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.
Group | Score | Limits |
---|---|---|
1 | 8 | , i.e. only one team will appear twice |
2 | 11 | and every team will appear exactly once in the first half and exactly once in the second half of the line |
3 | 14 | |
4 | 21 | and every team will appear twice |
5 | 22 | |
6 | 24 | No additional constraints |