P6230 [BalticOI 2019] Olympiads (Day2)
Background
**Translated from [BalticOI 2019](http://boi2019.eio.ee/tasks/) Day2 T3.** ***[Olympiads](http://boi2019.eio.ee/wp-content/uploads/2019/05/olymp.en_.pdf)***
Description
Two neighboring cities send a team of $K$ people every year to compete in $K$ events. Each contestant participates in all $K$ events. In a single event, the team’s score is the highest score achieved by any single member of the team in that event. The team’s total score is the sum of the team scores over all events.
Here is an example with $K = 3$:
| | Event 1 | Event 2 | Event 3 |
| :--------: | :-----: | :-----: | :-----: |
| Contestant 1 | 4 | 5 | 3 |
| Contestant 2 | 7 | 3 | 6 |
| Contestant 3 | 3 | 4 | 5 |
| **Team score** | 7 | 5 | 6 |
The total score of the team in these three events is $7 + 5 + 6 = 18$.
The two cities have started debating not only which city has the best team, but also which city has the $C$-th best team. Here, $C = 1$ means the best team (i.e., the team with the highest total score), $C = 2$ means the second best team, and so on.
Your task is to find, for one city, the score of the $C$-th best team in that city. Two teams are considered different if and only if they differ by at least one member.
Input Format
The first line contains three integers $N, K, C$, where $N$ is the number of candidate contestants in the city, $K$ is the team size, and $C$ indicates that you need to find the $C$-th best team.
The next $N$ lines each contain $K$ integers. In the $i$-th line, the $j$-th number is the score of contestant $i$ in event $j$.
It is guaranteed that $K \leq N$, the number of possible teams is at least $C$, and each contestant’s score does not exceed $10^6$.
Output Format
Output one integer: the score of the city’s $C$-th best team.
Explanation/Hint
The constraints for each subtask are as follows:
- Subtask 1 (13 points): $1 \leq N \leq 500, 1 \leq K \leq 2, 1 \leq C \leq 2000$;
- Subtask 2 (31 points): $1 \leq N \leq 40, 1 \leq K \leq 6, 1 \leq C \leq 2000$;
- Subtask 3 (24 points): $1 \leq N \leq 500, 1 \leq K \leq 6, 1 \leq C \leq 2000$,and all scores do not exceed $10$;
- Subtask 4 (32 points): $1 \leq N \leq 500, 1 \leq K \leq 6, 1 \leq C \leq 2000$;
Translated by ChatGPT 5