1979: [USACO 2023 January Contest Bronze] Problem 2. Air Cownditioning II
题目描述
With the hottest recorded summer ever at Farmer John's farm, he needs a way to cool down his cows. Thus, he decides to invest in some air conditioners.
Farmer John's cows () live in a barn that contains a sequence of stalls in a row, numbered . Cow occupies a range of these stalls, starting from stall and ending with stall . The ranges of stalls occupied by different cows are all disjoint from each-other. Cows have different cooling requirements. Cow must be cooled by an amount , meaning every stall occupied by cow must have its temperature reduced by at least units.
The barn contains air conditioners, labeled (). The th air conditioner costs units of money to operate () and cools the range of stalls starting from stall and ending with stall . If running, the th air conditioner reduces the temperature of all the stalls in this range by (). Ranges of stalls covered by air conditioners may potentially overlap.
Running a farm is no easy business, so FJ has a tight budget. Please determine the minimum amount of money he needs to spend to keep all of his cows comfortable. It is guaranteed that if FJ uses all of his conditioners, then all cows will be comfortable.
输入
The first line of input contains and .
The next lines describe cows. The th of these lines contains , , and .
The next lines describe air conditioners. The th of these lines contains , , , and .
For every input other than the sample, you can assume that .
输出
样例输入
2 4
1 5 2
7 9 3
2 9 2 3
1 6 2 8
1 2 4 2
6 9 1 5
样例输出
10