Homework
Time limit2sMemory limit512 MB
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.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Simulation, Implementation
- Solved
- No attempts yet
Problem
Taro 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 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 is empty, he plays a video game and does no homework that day, even when the other course still has unfinished assignments. Otherwise, let be the assignments of with the nearest deadline; he finishes the one with the smallest ID in .
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.
Input
The input consists of a single test case in the following format.
n m
s1 t1
.
.
.
sn tn
The first line contains two integers and with . Here is the total number of assignments in this semester and is the number of assignments of the mathematics course, so the informatics course has assignments. Assignment IDs run from 1 to : IDs 1 through belong to mathematics, and the rest belong to informatics. The next lines give the schedule of the assignments. The -th of them contains two integers and with . Assignment is given to Taro on day of the semester, and its deadline is the end of day .
Output
In the first line, print the maximum number of assignments Taro finishes. In the second line, print the minimum number.