Dates
Time limit2sMemory limit512 MB
Choose girls and assign each chosen girl a day in her interval, with day x used at most a_x times, to maximize total pleasure.
- Level
Hard8 of 10
- Topics
- Greedy, Segment tree, Intervals, Sorting
- Solved
- No attempts yet
Statement
Ilya loves dating. He plans dates for the next days, numbered from 1 to . For each day , he can plan at most dates.
Ilya has known girls, numbered from 1 to . Girl is willing to go on a date with him at most once, on any day in , and Ilya gets pleasure for dating her. For every , and .
Ilya wants to choose some of the girls and the days of their dates to maximize the total pleasure.
Input
The first line contains two integers and (). The next line contains integers (). The next lines each contain three integers , , and (, ).
Output
Print one integer: the maximum total pleasure Ilya can get.