欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

Hot Days Codeforces Round #132 (Div. 2) D(贪心)_html/css_WEB-ITnose

程序员文章站 2022-05-05 09:01:35
...
Description

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 ti 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 ti?+?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 Ti degrees inside, each of the schoolchild in the bus demands compensation for the uncomfortable conditions. The compensation is as large as xi 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 costi 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?≤?105; 1?≤?m?≤?106) ? 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 ti, Ti, xi and costi (1?≤?ti,?Ti,?xi,?costi?≤?106). 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 %I64dspecifier.

Sample Input

Input

2 1030 35 1 10020 35 10 10

Output

120

Input

3 10010 30 1000 15 10 1000 310 40 1000 100000

Output

200065

Hint

In the first sample the organizers will use only one bus to travel through the first region. However, the temperature in the bus will equal30?+?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.


题意:n个城市,m个人,每一个城市有一个温度t,车内的温度不能超过T,否者赔偿每个人x元,每一辆车的价格c,那个车内的温度为t加车内的人,对于每一个站,你可以选择坐计量车,求花费最小?


思路:对于每一个站,如果TT;


那么就要考虑了


现在假设所有人在一辆车,价格为c+m*x;

如果有一部分人出去租车,发现用的钱少一点,那么那一辆车最好坐满,否者空出来的位置可以坐的人就在那个已经满的车内需要补偿,

如果一部分人出去发现划算,那么为什么在出去一部分呢?这样想来就只有两种情况了

1‘ 所有人在一辆车上

2 每个车都不超过温度T,但是都坐满了


好了,上代码了:


#include#include#include#includeusing namespace std;#define N 1000100typedef __int64 ll;ll n,m,t,T,x,c;int main(){	ll ans;	while(~scanf("%I64d%I64d",&n,&m))	{		ans=0;		while(n--)		{			scanf("%I64d%I64d%I64d%I64d",&t,&T,&x,&c);			if(T