luogu#P7867. 「EVOI-RD1」马戏团

「EVOI-RD1」马戏团

Background

WuuTue owns a circus. The circus goes on tour around the country, and recently WuuTue's circus arrived in City T.

Problem Description

City T has a special performance street. The street is a straight road running from west to east, and there are nn stages on the street from west to east, numbered 1,2,,n1, 2, \dots, n.

WuuTue plans to hold mm performances on the performance street in City T. The ii-th performance occupies a consecutive range of stages from lil_i to rir_i (including lil_i and rir_i). At the same time, WuuTue knows that the ii-th performance will earn viv_i yuan.

Since the stages on the performance street are designed for human performances, if they are to be used for animal performances, they need to be reinforced. Reinforcing the ii-th stage costs cic_i yuan, and it only needs to be done once and can be reused. That is, if multiple performances use stage ii, the reinforcement cost only needs to be paid once.

Of course, if WuuTue finds that a performance may not be profitable due to high reinforcement costs, they may cancel that performance.

Because WuuTue is too weak, please help WuuTue calculate the maximum amount of money they can earn.

Input Format

The first line: two space-separated integers nn and mm, representing the number of stages and the number of performances.

Lines 22 to n+1n+1: each line contains 11 integer. The integer on line i+1i+1 is the cost cic_i to reinforce stage ii.

Lines n+2n+2 to n+m+1n+m+1: each line contains 33 space-separated integers. The 33 integers lil_i, rir_i, viv_i on line n+i+1n+i+1 indicate that the ii-th performance needs to occupy consecutive stages from lil_i to rir_i, and it can earn viv_i yuan.

Output Format

One line: one integer, representing the maximum profit WuuTue can obtain.

7 4
3
2
3
2
1
2
3
1 2 5
2 3 5
3 5 3
7 7 5
4
2 1
0
3
1 2 5
2
3 1
10
10
10
1 3 10
0

Hint

This problem uses bundled testdata.

For 20%20\% of the testdata, 1n,m1001 \le n , m \le 100.

For another 20%20\% of the testdata, vi=ci=1v_i = c_i = 1.

For another 20%20\% of the testdata, li=ril_i = r_i.

For 100%100\% of the testdata, $1 \le n , m \le 10^6 , 0 \le v_i , c_i \le 10^9 , 1 \le l_i \le r_i \le n$。

Translated by ChatGPT 5