Treatment Project
Time limit2sMemory limit512 MB
Choose treatment projects with the smallest total cost so that no citizen stays infected. Each project treats a range of consecutive houses on one day.
- Level
Hard8 of 10
- Topics
- Shortest path, Graph, Segment tree, Sorting
- Solved
- No attempts yet
Problem
There are houses in the JOI kingdom, numbered from 1 to . The houses lie on a line in numerical order. Each house has one citizen. The citizen living in house () is called citizen .
A new virus has infected every citizen. To deal with it, treatment projects are proposed. Project costs . Performing project has the following effect.
In the evening of day , every infected citizen with is treated.
The virus spreads to neighbors as follows. If citizen is infected in the morning of some day, then citizen (if ) and citizen (if ) become infected at noon of the same day. A treated citizen can be infected again.
Choose some of the projects so that, after all chosen projects are performed, no citizen is infected. Several projects may be performed on the same day.
Determine whether this condition can be satisfied. If it can, find the minimum total cost.
Input
The first line contains and . Each of the next lines contains , , , and .
N M
T1 L1 R1 C1
.
.
.
TM LM RM CM
Output
Print one line. If the condition cannot be satisfied, print -1. Otherwise, print the minimum total cost.
Constraints
- ()
- ()
- ()