Codeforces Beta Round 63 (Div. 2)
B
Bets
Codeforces
1200
原题
← AC →
翻译中…

In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.

翻译中…

To begin with friends learned the rules: in the race there are $*n*$ sections of equal length and $*m*$ participants. The participants numbered from $1$ to $*m*$. About each participant the following is known:

翻译中…
  • $*l*_{*i*}$ — the number of the starting section,
  • $*r*_{*i*}$ — the number of the finishing section ($*l*_{*i*} ≤ *r*_{*i*}$),
  • $*t*_{*i*}$ — the time a biathlete needs to complete an section of the path,
  • $*c*_{*i*}$ — the profit in roubles. If the $*i*$-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
翻译中…

The $*i*$-th biathlete passes the sections from $*l*_{*i*}$ to $*r*_{*i*}$ inclusive. The competitor runs the whole way in $(*r*_{*i*} - *l*_{*i*} + 1)·*t*_{*i*}$ time units. It takes him exactly $*t*_{*i*}$ time units to pass each section. In case of the athlete's victory on $*k*$ sections the man who has betted on him receives $*k*·*c*_{*i*}$ roubles.

翻译中…

In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.

翻译中…

We should also add that Nikita can bet on each section and on any contestant running in this section.

翻译中…

Help the friends find the maximum possible profit.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100$). Then follow $*m*$ lines, each containing 4 integers $*l*_{*i*}$, $*r*_{*i*}$, $*t*_{*i*}$, $*c*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*$, $1 ≤ *t*_{*i*}, *c*_{*i*} ≤ 1000$).

翻译中…

Output

翻译中…

Print a single integer, the maximal profit in roubles that the friends can get. In each of $*n*$ sections it is not allowed to place bets on more than one sportsman.

翻译中…

Note

翻译中…

In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.

翻译中…

In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.

翻译中…

样例

Input #1
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output #1
60
InputCopy OutputCopy
Input #2
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output #2
105
InputCopy OutputCopy
题目信息
题号
69B
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。