#P11085. [ROI 2019] 学生座位 (Day 2)
[ROI 2019] 学生座位 (Day 2)
Background
Translated from ROI 2019 D2T2.
The school wants to buy two-person desks for a new special classroom. These desks have types, and each type has different dimensions. A desk of type is suitable for students whose height is within the range from to (inclusive). For other students, sitting at this type of desk is uncomfortable. The discomfort is defined as the absolute difference between the student’s height and the nearest boundary of the suitable height range (that is, or ). If the desk is suitable for the student, the discomfort is .
For example, if , then a student with height has discomfort , a student with height has discomfort , and a student with height has discomfort .
Students from classes will take turns coming to the special classroom for lessons, and each class has exactly students. The purchased desks will be placed in the classroom, and each desk seats two students.
Problem Description
You are given the heights of every student in every class. You need to buy desks and arrange seats for the students of each class so that the total discomfort of all students studying in the classroom is minimized.
Write a program that, based on the information of each desk type and the students’ heights in each class, determines the minimum possible sum of discomfort that can be achieved by purchasing desks and arranging seats in an optimal way.
Input Format
The first line contains three integers , representing the number of classes that will study in the classroom, the number of desks to buy, and the number of different desk types.
Each of the next lines contains two integers and , describing the suitable height range for desk type .
Each of the next lines contains integers , the heights of the students in that class.
Output Format
Output one number , the minimum possible sum of discomfort after buying desks and arranging seats in an optimal way.
1 2 2
5 25
50 90
60 5 10 40
10
2 3 3
200 400
300 500
100 600
300 330 440 40 30 300
150 250 350 450 550 300
130
1 3 4
10 100
200 200
10 100
300 1000
5 10 20 15 200 90
105
Hint
Explanation of Sample : In the first sample, only one class studies in the classroom. You should buy one desk of each type, then seat the students with heights and at the first type of desk, and the students with heights and at the second type of desk. Then only the student with height will feel uncomfortable, with discomfort .
| Subtask | Score | Special property | Special property | Special property | Other special properties |
|---|---|---|---|---|---|
For of the testdata, $1 \le m\times n \le 200000,2 \le k \le 200000,1 \le L_i \le R_i \le 10^9,1 \le h_i \le 10^9$。
Translated by ChatGPT 5