eolymp
bolt
Try our new interface for solving problems
Problems

Schedule

Schedule

Scripture one, scripture two ... \textit{From the inventory of the church} Arseny came again to the university and going to the schedule, I found out that today is read exactly \textbf{N} lectures. He also found time start and end of each lecture, and the names of the lecturers. Now he's deep in thought - which should go well. Since Arseny with a just one notebook, he can not visit more than \textbf{K} different lectures, or he is simply nowhere to be abstract. Lectures are held in different classrooms, so that at any given time Arseniy may be present not more than one lecture. But he can go to lectures at any time, without even waiting for the end, and comes after the start. For every minute spent in the lecture, Arseny receives \textbf{1} point of knowledge. Naturally, he wants to maximize the total knowledge acquired during the whole day. Help Arseny understand what it can achieve. Arseny very well-versed in his department, so that time spent on transitions between lecture transitions can be neglected. \InputFile The first line of the input file contains two numbers separated by a space of \textbf{N} and \textbf{K} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100000}, \textbf{0} ≤ \textbf{K} ≤ \textbf{100}). Next N lines, each of which contains two numbers \textbf{s_i} and \textbf{e_i} (_0 ≤ \textbf{s_i} ≤ \textbf{e_i} ≤ \textbf{10^9}), specifying the beginning and end of the i-th lecture, respectively. Time is in minutes since the arrival of Arseny. All numbers in the input file are integers. \OutputFile Bring a single number - the maximum number of items of knowledge that will be able to Arseny for that day (day Arseny ends no earlier than end the last lecture).
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
3 2
1 2
3 6
5 8
Output example #1
5