Olympic Country Ranking
InterviewTime limit1sMemory limit128 MB
Count how many countries beat country K on gold, then silver, then bronze medals, and report its rank.
Problem
At the Olympics the point is to take part, so no official ranking of countries is kept. Still, many people care how their own country does, so an unofficial ranking is common. Given the number of gold, silver, and bronze medals each country won, the usual rule for deciding which country did better is:
- The country with more gold medals ranks higher.
- If the gold counts are equal, the country with more silver medals ranks higher.
- If both gold and silver counts are equal, the country with more bronze medals ranks higher.
Each country is identified by an integer from 1 to . A country's rank is defined as (the number of countries that did strictly better than it) . Two countries with identical gold, silver, and bronze counts share the same rank. For example, if country 1 won 1 gold and 1 silver, countries 2 and 3 each won 1 silver, and country 4 won no medals, then country 1 is 1st, countries 2 and 3 tie for 2nd, and country 4 is 4th. In this case there is no 3rd place.
Given each country's gold, silver, and bronze medal counts, write a program that reports the rank of a given country.
Input
The first line contains the number of countries () and the country number () whose rank you want, separated by a space. Each country is identified by an integer from 1 to . Each of the next lines contains a country's number followed by the gold, silver, and bronze medal counts it won, separated by spaces. The countries are not necessarily listed in numeric order. The total number of medals is at most .
Output
Print a single integer on one line: the rank of country . The rank must follow the rule defined above.