#P7867. Maximizing Net Profit on a Performance Street
Maximizing Net Profit on a Performance Street
Maximizing Net Profit on a Performance Street
WuuTue is planning a series of performances on a straight east‐west street in city T. The street has stages numbered from to (from west to east). There are proposed performances; the –th performance can be held on all consecutive stages from to (inclusive) and will yield a revenue of dollars if held. However, the stages are originally built for human performances. In order to allow animal performances, each stage must be strengthened at a cost. Strengthening stage costs dollars and each stage only needs to be strengthened once, even if it is used for multiple performances.
WuuTue may choose to cancel any performance if its revenue does not cover the strengthening costs. When a set of performances is chosen, the net profit is computed as
where the union set of stages
is strengthened (each stage cost is counted only once).
Your task is to help WuuTue choose a subset of performances (possibly cancelling some) so that the net profit is maximized. Note that it is allowed that the performances in overlap. If no performance yields a positive net profit, you may choose to cancel all performances (resulting in a net profit of ).
inputFormat
The first line contains two integers and --- the number of stages and the number of proposed performances.
The second line contains integers , where is the cost to strengthen stage .
Each of the following lines contains three integers , , and , indicating that the –th performance requires consecutive stages from to and will bring a revenue of dollars.
outputFormat
Output a single integer --- the maximum net profit achievable.
sample
5 3
2 2 2 2 2
1 3 10
2 5 15
4 5 10
25