1979: [USACO 2023 January Contest Bronze] Problem 2. Air Cownditioning II

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:1 解决:1

题目描述

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 N cows (1N20) live in a barn that contains a sequence of stalls in a row, numbered 1100. Cow i occupies a range of these stalls, starting from stall si and ending with stall ti. The ranges of stalls occupied by different cows are all disjoint from each-other. Cows have different cooling requirements. Cow i must be cooled by an amount ci, meaning every stall occupied by cow i must have its temperature reduced by at least ci units.

The barn contains M air conditioners, labeled 1M (1M10). The ith air conditioner costs mi units of money to operate (1mi1000) and cools the range of stalls starting from stall ai and ending with stall bi. If running, the ith air conditioner reduces the temperature of all the stalls in this range by pi (1pi106). 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 N and M.

The next N lines describe cows. The ith of these lines contains siti, and ci.

The next M lines describe air conditioners. The ith of these lines contains aibipi, and mi.

For every input other than the sample, you can assume that M=10.

输出

Output a single integer telling the minimum amount of money FJ needs to spend to operate enough air conditioners to satisfy all his cows (with the conditions listed above).

样例输入

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

提示

One possible solution that results in the least amount of money spent is to select those that cool the intervals [2,9][1,2], and [6,9], for a cost of 3+2+5=10.

来源/分类