Stipe
InterviewTime limit1sMemory limit1024 MB
Pick K people who are each at least as old as everyone skipped, minimizing how many people are turned away before the last dose.
Problem
Stipe is in charge of a vaccination line. There are N people in the line, and the age of each person is known. When Stipe shouts 'Sljedeći!' ('Next!'), the person at the front of the line steps forward. Stipe then either lets that person get vaccinated or tells them to come back another day.
There are K vaccine doses, and Stipe makes sure all of them are used. After K people have been vaccinated, Stipe announces that there are no doses left and sends the rest of the people in line home.
For Stipe this would be simple, if not for the risk that news portals report at the end of the day: they vaccinated the younger one but not the older one! To prevent this, Stipe makes sure there is no pair of people (X, Y) such that X is vaccinated, Y is not, and X is younger than Y.
Stipe also wants the number of people he sends home while vaccines are still left, that is, before the last person is vaccinated, to be as small as possible. How many people will Stipe send home while vaccines are still left?
Input
The first line contains natural numbers N () and K (). Each of the next N lines contains three non-negative integers G (), M (), and D (), the age of the people in line from first to last, in years, months, and days.
Output
Print a single line with the number of people Stipe sends home while vaccines are still left.
Hint
Sample 1: the first and second people are vaccinated, and the third person is sent home when the vaccines run out. No one is sent home while vaccines are still left.
Sample 2: only the third person is vaccinated, and the first two people are sent home while vaccines are still left.
Sample 3: the first and third people are vaccinated. The second and fourth people are sent home, but only the second is sent home while vaccines are still left. The fourth is sent home when the vaccines run out.