Perfume
Time limit8sMemory limit1024 MB
Place K perfume bottles on a line to maximize the total weight of intervals that contain at least one bottle position.
- Level
Medium7 of 10
- Topics
- Intervals, Greedy, Shortest path
- Solved
- No attempts yet
Problem
The year is almost over. Christmas carols and small twinkling lights line the streets. Hope and relief show on people's faces, but some faces carry regret and anxiety as a faint shadow.
Jaemin is happy to see 2021 go, and tonight he has decided to give people happiness.
Tonight, people will spend their time walking along a road on an infinitely long vertical number line.
The -th person starts walking in the positive direction from position and leaves the road at position .
Jaemin has bottles of perfume. The perfume has a magical power that makes whoever smells it happy. The amount differs per person: the -th of the people gains happiness when they smell it.
Jaemin wants to place the perfume bottles on the road so that the total happiness is maximized. However, because of the strong wind, a person can smell a bottle only if they pass exactly the position where it is placed. A person can smell a bottle at an endpoint of their path, and even if they smell several bottles, they gain happiness only once.
Help Jaemin give happiness to people and close out the year.
Input
The first line contains and , separated by a space. ()
Each of the next lines contains , , and , separated by spaces. (, )
Output
Print the maximum total happiness the people can gain when the bottles are placed optimally, on one line.