#P3440. [POI 2006] SZK-Schools
[POI 2006] SZK-Schools
Description
There are schools in country B, each with an ID from .
Due to lax administration, it may happen that two schools share the same ID, and some IDs may be unused.
Now the king decides to reassign IDs to all schools so that any two schools have different IDs.
However, changing IDs is a heavy workload, and schools do not want their IDs to change too much. Each school has an acceptable interval for its new ID , and a unit cost . If a school’s old ID is and the new ID is , then the cost to change this school’s ID is .
You need to tell the king the minimum total cost to complete the renumbering, or state that it is impossible.
Input Format
The first line contains an integer .
Then follow lines, each containing four integers , meaning that school has old ID , its new ID must be in the range , and its unit cost is .
Output Format
If there is no assignment such that any two schools have different IDs, output NIE.
Otherwise, output a single integer, the minimum total cost.
5
1 1 2 3
1 1 5 1
3 2 5 5
4 1 5 10
3 3 3 1
9
Hint
Constraints
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号