Greedy Pie Eaters

시간 제한2초메모리 제한512 MB

요약
각 소가 자신이 좋아하는 구간 [l, r]에서 최소 한 개의 파이를 먹도록 순서를 정할 때, 선택한 소들의 무게 합의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 구간, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Farmer John has MM cows, conveniently labeled 1…M1 \ldots M, who enjoy the occasional change of pace from eating grass. As a treat for the cows, Farmer John has baked NN pies (1≤N≤3001 \leq N \leq 300), labeled 1…N1 \ldots N. Cow ii enjoys pies with labels in the range \[l_i,r_i]\[l\_i, r\_i] (from l_il\_i to r_ir\_i inclusive), and no two cows enjoy the exact same range of pies. Cow ii also has a weight, w_iw\_i, which is an integer in the range 1…1061 \ldots 10^6.

Farmer John may choose a sequence of cows c_1,c_2,…,c_K,c\_1,c\_2,\ldots, c\_K, after which the selected cows will take turns eating in that order. Unfortunately, the cows don't know how to share! When it is cow c_ic\_i's turn to eat, she will consume all of the pies that she enjoys --- that is, all remaining pies in the interval \[l_c_i,r_c_i]\[l\_{c\_i},r\_{c\_i}]. Farmer John would like to avoid the awkward situation occurring when it is a cows turn to eat but all of the pies she enjoys have already been consumed. Therefore, he wants you to compute the largest possible total weight (w_c_1+w_c_2+…+w_c_Kw\_{c\_1}+w\_{c\_2}+\ldots+w\_{c\_K}) of a sequence c_1,c_2,…,c_Kc\_1,c\_2,\ldots, c\_K for which each cow in the sequence eats at least one pie.

입력

The first line contains two integers NN and MM (1≤M≤N(N+1)2)\left(1\le M\le \frac{N(N+1)}{2}\right).

The next MM lines each describe a cow in terms of the integers w_i,l_iw\_i, l\_i, and r_ir\_i.

출력

Print the maximum possible total weight of a valid sequence.

힌트

In this example, if cow 1 eats first, then there will be nothing left for cow 2 to eat. However, if cow 2 eats first, then cow 1 will be satisfied by eating the second pie only.

예제1

  1. 예제 1

    입력
    2 2
    100 1 2
    100 1 1
    
    예상 출력
    200