Hacking
Time limit1sMemory limit1024 MB
Given preliminary scores and Ivaylo's rank, find the minimum number of other participants' solutions he must hack to gain 100 each and finish first alone.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Implementation, Brute force
- Solved
- No attempts yet
Problem
Ivaylo takes part in informatics contests every week, and they run by the following rules.
Participants are given problems to solve. When they solve a problem, they submit it to the grading system. During the contest, grading is done with a small set of tests called pretests. The result of the pretest grading is reported to the participant right after grading. If the program gives the correct result on all the tests, the participant is awarded preliminary points for that problem. The participant can then lock that problem so that he can watch the solutions of other participants for that problem.
A participant can hack another participant's solution. In that case the hacked solution gives its author no points at all, and the hacking solution receives 100 points. If a solution is not hacked and passes the full set of tests after the end of the contest, the participant receives the points he earned in advance for that problem. At the end of the contest, the total number of points each participant has collected for solving problems and for hacking is computed. The winner is the participant with the most points.
Only five minutes remain until the end of the contest. Ivaylo has already solved all the problems he could (his solutions will also pass the full set of tests after the end of the contest) and he has locked them. Now he can climb the standings only by hacking other participants' solutions.
Ivaylo's coach demands that he take first place outright. If Ivaylo takes a place other than first (or shares first place with another participant), he will be punished: he will lose the chance to play several computer games. Naturally, Ivaylo is a bit lazy and always tries to achieve the desired result with the least effort.
You can help him by writing the program hacks, which finds the minimum number of hacks Ivaylo has to make in order to take first place. If it is impossible for him to take first place, print the number .
We assume that Ivaylo can hack any solution of any participant, and that all solutions he does not hack will pass the full set of tests (and thus bring points to the corresponding participant). Ivaylo is so strong at programming that he can perform hacks instantly, meaning that in the remaining five minutes he can hack an unlimited number of problems. Ivaylo can break other participants' solutions only for the problems he has solved himself.
Input
The first line of the standard input contains three integers: the number of problems , the number of participants , and Ivaylo's position in the current standings (the standings are not sorted by the participants' preliminary points).
Each of the following lines contains integers; the -th of these lines () contains the values , , the preliminary points of the -th participant for problem . If , this means that this participant has not yet submitted problem , or his solution has not passed the pretests.
Output
On the first line of the standard output, the program must print one integer: the minimum number of hacks Ivaylo has to make in order to take first place outright, or the number if this is impossible.
Constraints
Hint
In the first example, Ivaylo can hack the second participant's solution to the first problem, for which he will get 100 points and take first place with points.
In the second example, Ivaylo must hack the solutions of two contestants; then he will gain points and take the lead.
In the third example, Ivaylo cannot gain a single point, because no participant has solved any problem and all contestants share first place. So the answer is .