Under construction

Still being built. Things may change

Dates

Time limit2sMemory limit512 MB

Summary
Choose girls and assign each chosen girl a day in her interval, with day x used at most a_x times, to maximize total pleasure.
Level

Hard8 of 10

Topics
Greedy, Segment tree, Intervals, Sorting
Solved
No attempts yet

Statement

Ilya loves dating. He plans dates for the next tt days, numbered from 1 to tt. For each day xx, he can plan at most axa_x dates.

Ilya has nn known girls, numbered from 1 to nn. Girl ii is willing to go on a date with him at most once, on any day in [li,ri][l_i, r_i], and Ilya gets pip_i pleasure for dating her. For every i<ni < n, li≤li+1l_i \le l_{i+1} and ri≤ri+1r_i \le r_{i+1}.

Ilya wants to choose some of the girls and the days of their dates to maximize the total pleasure.

Input

The first line contains two integers nn and tt (1≤n,t≤3000001 \le n, t \le 300000). The next line contains tt integers a1,a2,…,ata_1, a_2, \ldots, a_t (0≤ai≤n0 \le a_i \le n). The next nn lines each contain three integers lil_i, rir_i, and pip_i (1≤li≤ri≤t1 \le l_i \le r_i \le t, 1≤pi≤1091 \le p_i \le 10^9).

Output

Print one integer: the maximum total pleasure Ilya can get.

Examples1

  1. Example 1

    Input
    3 5
    0 1 0 1 0
    1 2 2
    2 4 1
    3 5 5
    
    Expected output
    7