Baltic OI '19 P6 - Olympiads
View as PDFBaltic Olympiad in Informatics: 2019 Day 2, Problem 3
Two neighbouring cities send each year a team of  contestants to compete in 
 different
events. Each contestant participates in all the events. The score of a team in an event is the
highest score earned by any of that team's contestants in that event. The total score of a team
is the sum of the scores of the team over all events. For example, if 
 and the contestants
score 
, 
, and 
 then the scores for the team in the events are 
 and the total score of the team is 
.
Each city has a set of eligible contestants they can send to the competition. The cities have
started arguing about not only which city has the best team, but also about which city has the
better -th best team for some integer 
, where 
 corresponds to the best team, 
 is
the second best team, and so on.
You are tasked with helping one of the cities finding out the expected score its -th best team,
considering all the different 
-member teams they could compose from their eligible contestants.
Two teams are considered different if they have at least one contestant different.
Input Specification
The first line contains the integers , 
, and 
, where 
 is the total number of eligible
contestants in a city, 
 the size of the team 
, and 
 the index of the team we're
interested in (
 does not exceed the number of possible 
-member teams).
Each of the following  lines contains 
 non-negative integers, the expected scores of one eligible
contestant in the 
 events. No score will be greater than 
.
Output Specification
The only line should contain the total score of the -th best team.
Sample Input
5 4 4
7 0 4 9
3 0 8 4
1 1 3 7
5 1 3 4
4 2 2 9
Sample Output
24
There are  possible teams and they would score 
, 
, 
, 
, and 
 points, so the 
-th best score is 
.
Grading
The test groups satisfy the following conditions:
- (
points)
,
,
.
 - (
points)
,
,
.
 - (
points)
,
,
, no score is greater than
.
 - (
points)
,
,
.
 
Comments