#P6230. [BalticOI 2019] 奥运会 (Day2)

[BalticOI 2019] 奥运会 (Day2)

Description

Two neighboring cities send a team of KK people every year to compete in KK events. Each contestant participates in all KK 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=3K = 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=187 + 5 + 6 = 18.

The two cities have started debating not only which city has the best team, but also which city has the CC-th best team. Here, C=1C = 1 means the best team (i.e., the team with the highest total score), C=2C = 2 means the second best team, and so on.

Your task is to find, for one city, the score of the CC-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,CN, K, C, where NN is the number of candidate contestants in the city, KK is the team size, and CC indicates that you need to find the CC-th best team.

The next NN lines each contain KK integers. In the ii-th line, the jj-th number is the score of contestant ii in event jj.

It is guaranteed that KNK \leq N, the number of possible teams is at least CC, and each contestant’s score does not exceed 10610^6.

Output Format

Output one integer: the score of the city’s CC-th best team.

5 4 4
7 0 4 9
3 0 8 4
1 1 3 7
5 1 3 4
4 2 2 9
24

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 1010
  • Subtask 4 (32 points): $1 \leq N \leq 500, 1 \leq K \leq 6, 1 \leq C \leq 2000$;

Translated by ChatGPT 5