最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#132(Div.2)D.HotDays_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:57:41
文档

CodeforcesRound#132(Div.2)D.HotDays_html/css

CodeforcesRound#132(Div.2)D.HotDays_html/css_WEB-ITnose:D. Hot Days time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The official capital and the cultural capital of Berland are connected by a single road running th
推荐度:
导读CodeforcesRound#132(Div.2)D.HotDays_html/css_WEB-ITnose:D. Hot Days time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The official capital and the cultural capital of Berland are connected by a single road running th

D. Hot Days

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)

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

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 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,cost分别表示该地区的温度t,车内最大温度限制T,车内温度若超过T对每个孩子的赔偿x,坐车的费用cost,求最小的费用。

思路:1. 当 m <= (T-t) 时
最后的费用都为 : cost
2.m>(T-t) 时
有两种选择 一个是尽量做在一辆车上(对于补助费比较少时)
sum=m*x;
另一个是 尽量多做车,但是要保证车都坐满(刚好达到不要补助费的时候)。
sum=cost*( m%(T-t)==0? m/(T-t)+1: m/(T-t) );

代码:

#include #include #include #include #include #include #include #include #include #include #include #pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int main(){ __int64 n,m; while (~scanf("%I64d%I64d",&n,&m)) { __int64 t,T,x,c,ss1,ss2; __int64 ans=0; __int64 s1,s2; for (__int64 i=0;i

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

CodeforcesRound#132(Div.2)D.HotDays_html/css

CodeforcesRound#132(Div.2)D.HotDays_html/css_WEB-ITnose:D. Hot Days time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The official capital and the cultural capital of Berland are connected by a single road running th
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top