CF215D.Hot Days

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The official capital and the cultural capital of Berland are connected by a single road running through nn regions. Each region has a unique climate, so the ii -th (1<=i<=n)(1<=i<=n) region has a stable temperature of tit_{i} degrees in summer.

This summer a group of mm 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 ii -th region and has kk schoolchildren, then the temperature inside the bus is ti+kt_{i}+k degrees.

Of course, nobody likes it when the bus is hot. So, when the bus drives through the ii -th region, if it has more than TiT_{i} degrees inside, each of the schoolchild in the bus demands compensation for the uncomfortable conditions. The compensation is as large as xix_{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 ii -th region will cost the organizers costicost_{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.

输入格式

The first input line contains two integers nn and mm (1<=n<=105(1<=n<=10^{5} ; 1<=m<=106)1<=m<=10^{6}) — the number of regions on the way and the number of schoolchildren in the group, correspondingly. Next nn lines contain four integers each: the ii -th line contains tit_{i} , TiT_{i} , xix_{i} and costicost_{i} ( 1<=ti,Ti,xi,costi<=1061<=t_{i},T_{i},x_{i},cost_{i}<=10^{6} ). The numbers in the lines are separated by single spaces.

输出格式

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.

输入输出样例

  • 输入#1

    2 10
    30 35 1 100
    20 35 10 10
    

    输出#1

    120
    
  • 输入#2

    3 100
    10 30 1000 1
    5 10 1000 3
    10 40 1000 100000
    

    输出#2

    200065
    

说明/提示

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=4030+10=40 degrees and each of 1010 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=120100+10+10=120 rubles.

首页