QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#1909. Greedy Pie Eaters

统计

Farmer John has $M$ cows, conveniently labeled $1 \ldots M$, who enjoy the occasional change of pace from eating grass. As a treat for the cows, Farmer John has baked $N$ pies ($1 \leq N \leq 300$), labeled $1 \ldots N$. Cow $i$ enjoys pies with labels in the range $[l_i, r_i]$ (from $l_i$ to $r_i$ inclusive), and no two cows enjoy the exact same range of pies. Cow $i$ also has a weight, $w_i$, which is an integer in the range $1 \ldots 10^6$.

Farmer John may choose a sequence of cows $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_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}]$. 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}+\ldots+w_{c_K}$) of a sequence $c_1,c_2,\ldots, c_K$ for which each cow in the sequence eats at least one pie.

Scoring

  • Test cases 2-5 satisfy $N\le 50$ and $M\le 20$.
  • Test cases 6-9 satisfy $N\le 50.$

Input Format

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

The next $M$ lines each describe a cow in terms of the integers $w_i, l_i$, and $r_i$.

Output Format

Print the maximum possible total weight of a valid sequence.

Sample Input

2 2
100 1 2
100 1 1

Sample Output

200

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.

Problem credits: Benjamin Qi

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.