#P7867. Maximizing Net Profit on a Performance Street

    ID: 21052 Type: Default 1000ms 256MiB

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 nn stages numbered from 11 to nn (from west to east). There are MM proposed performances; the ii–th performance can be held on all consecutive stages from lil_i to rir_i (inclusive) and will yield a revenue of viv_i 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 jj costs cjc_j 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 SS of performances is chosen, the net profit is computed as

Profit=iSvijUcj,Profit = \sum_{i\in S} v_i - \sum_{j \in U} c_j,

where the union set of stages

U=iS{li,li+1,,ri}U = \bigcup_{i\in S} \{l_i,l_i+1,\dots,r_i\}

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 SS overlap. If no performance yields a positive net profit, you may choose to cancel all performances (resulting in a net profit of 00).

inputFormat

The first line contains two integers nn and MM --- the number of stages and the number of proposed performances.
The second line contains nn integers c1,c2,,cnc_1, c_2,\dots,c_n, where cjc_j is the cost to strengthen stage jj.
Each of the following MM lines contains three integers lil_i, rir_i, and viv_i, indicating that the ii–th performance requires consecutive stages from lil_i to rir_i and will bring a revenue of viv_i 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