Given n assignments split into two courses with release days and deadlines, simulate fixed tie-break rules over adaptive coin choices and find the maximum and minimum number he can finish.
Hard8Dynamic programmingGreedySimulationImplementationNo attempts yetTime limit2sMemory limit512 MBTaro is a student at Ibaraki College of Prominent Computing. This semester he takes two courses, mathematics and informatics. After a class the teacher may assign homework. A single class can produce several assignments, and each assignment may have its own deadline. Every assignment carries a distinct ID number.
Every day after school Taro finishes at most one assignment, in the following way. He first flips a coin to decide which course to work on. Let S be the set of all assignments of the chosen course that have already been given, are still unfinished, and whose deadline has not passed. If S is empty, he plays a video game and does no homework that day, even when the other course still has unfinished assignments. Otherwise, let T⊆S be the assignments of S with the nearest deadline; he finishes the one with the smallest ID in T.
The number of assignments Taro finishes by the end of the semester depends on the coin flips. Given the schedule of the assignments, compute the maximum and the minimum number of assignments Taro finishes. The semester runs from day 1 to day 400, and Taro flips the coin on every one of those days.
The input consists of a single test case in the following format.
n m
s1 t1
.
.
.
sn tn
The first line contains two integers n and m with 1≤m<n≤400. Here n is the total number of assignments in this semester and m is the number of assignments of the mathematics course, so the informatics course has n−m assignments. Assignment IDs run from 1 to n: IDs 1 through m belong to mathematics, and the rest belong to informatics. The next n lines give the schedule of the assignments. The i-th of them contains two integers si and ti with 1≤si≤ti≤400. Assignment i is given to Taro on day si of the semester, and its deadline is the end of day ti.
In the first line, print the maximum number of assignments Taro finishes. In the second line, print the minimum number.