Codeforces Round 132 (Div. 2)
D
Hot Days
Codeforces
1900
原题
← CE →
翻译中…

The official capital and the cultural capital of Berland are connected by a single road running through $*n*$ regions. Each region has a unique climate, so the $*i*$-th $(1 ≤ *i* ≤ *n*)$ region has a stable temperature of $*t*_{*i*}$ degrees in summer.

翻译中…

This summer a group of $*m*$ schoolchildren wants to get from the official capital to the cultural capital to visit museums and sights. The trip organizers transport the children between the cities in buses, but sometimes it is very hot. Specifically, if the bus is driving through the $*i*$-th region and has $*k*$ schoolchildren, then the temperature inside the bus is $*t*_{*i*} + *k*$ degrees.

翻译中…

Of course, nobody likes it when the bus is hot. So, when the bus drives through the $*i*$-th region, if it has more than $*T*_{*i*}$ degrees inside, each of the schoolchild in the bus demands compensation for the uncomfortable conditions. The compensation is as large as $*x*_{*i*}$ rubles and it is charged in each region where the temperature in the bus exceeds the limit.

翻译中…

To save money, the organizers of the trip may arbitrarily add or remove extra buses in the beginning of the trip, and between regions (of course, they need at least one bus to pass any region). The organizers can also arbitrarily sort the children into buses, however, each of buses in the $*i*$-th region will cost the organizers $*cost*_{*i*}$ rubles. Please note that sorting children into buses takes no money.

翻译中…

Your task is to find the minimum number of rubles, which the organizers will have to spend to transport all schoolchildren.

翻译中…

Input

翻译中…

The first input line contains two integers $*n*$ and $*m*$ $(1 ≤ *n* ≤ 10^{5}$; $1 ≤ *m* ≤ 10^{6})$ — the number of regions on the way and the number of schoolchildren in the group, correspondingly. Next $*n*$ lines contain four integers each: the $*i*$-th line contains $*t*_{*i*}$, $*T*_{*i*}$, $*x*_{*i*}$ and $*cost*_{*i*}$ ($1 ≤ *t*_{*i*}, *T*_{*i*}, *x*_{*i*}, *cost*_{*i*} ≤ 10^{6}$). The numbers in the lines are separated by single spaces.

翻译中…

Output

翻译中…

Print the only integer — the minimum number of roubles the organizers will have to spend to transport all schoolchildren.

翻译中…

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

翻译中…

Note

翻译中…

In the first sample the organizers will use only one bus to travel through the first region. However, the temperature in the bus will equal $30 + 10 = 40$ degrees and each of $10$ schoolchildren will ask for compensation. Only one bus will transport the group through the second region too, but the temperature inside won't exceed the limit. Overall, the organizers will spend $100 + 10 + 10 = 120$ rubles.

翻译中…

样例

Input #1
2 10
30 35 1 100
20 35 10 10
Output #1
120
InputCopy OutputCopy
Input #2
3 100
10 30 1000 1
5 10 1000 3
10 40 1000 100000
Output #2
200065
InputCopy OutputCopy
题目信息
题号
215D
时间限制
2 s
内存限制
256 MB
标签
贪心

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