Productivity improvement
Time limit2sMemory limit256 MB
Partition all workers into exactly p nonempty lines to maximize the sum of each line's common overlapping work time.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Intervals
- Solved
- No attempts yet
Problem
ACME Inc. rebuilt its factory to raise productivity. The factory has production lines that are independent and identical, and each line gets some workers.
Machines do all of the work, so the production rate is the same no matter how many workers stand at a line. Safety rules allow a line to run only while every worker assigned to it is on duty. The productivity of a line is therefore the length of the time span in which all of its workers are at work together. To keep the workers proud of their line, the productivity of every line must be greater than 0.
Labor law forbids ACME from firing anyone, so all workers have to be assigned to a line, and no line may be left empty. The productivity of the factory is the sum of the productivities of the lines. What is the largest productivity the new factory can reach?
Input
The first line contains the number of workers and the number of production lines ().
Each of the next lines contains the arrival time and the leaving time of one worker ().
At least one valid assignment is guaranteed to exist.
Output
Print the maximum productivity of the factory on one line.