Hot Days Codeforces Round #132 (Div. 2) D(贪婪)

本文介绍了一种解决学校儿童从一地到另一地旅行时如何最小化成本的算法。该算法考虑了不同区域的温度限制、补偿费用及车辆成本等因素,通过合理分配乘车人数来降低总开销。

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 ≤ 1051 ≤ 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 tiTixi 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 10
30 35 1 100
20 35 10 10
Output
120
Input
3 100
10 30 1000 1
5 10 1000 3
10 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加车内的人。对于每个站,你能够选择坐计量车,求花费最小?


思路:对于每个站,假设T<t 那么一辆车。假设t+m<=T,一辆车。假设t<T可是t+m>T;


那么就要考虑了


如今如果全部人在一辆车,价格为c+m*x;

假设有一部分人出去租车,发现用的钱少一点,那么那一辆车最好坐满,否者空出来的位置能够坐的人就在那个已经满的车内须要补偿,

假设一部分人出去发现划算。那么为什么在出去一部分呢?这样想来就仅仅有两种情况了

1‘ 全部人在一辆车上

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


好了,上代码了:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define N 1000100

typedef __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<=t)
			{
				ans+=x*m+c;
				continue;
			}
			if(t+m<=T)
			{
				ans+=c;
				continue;
			}
			ll temp=T-t;
			temp=m%temp?

m/temp+1:m/temp; ans+=min(x*m+c,c*temp); } printf("%I64d\n",ans); } return 0; }








版权声明:本文博客原创文章,博客,未经同意,不得转载。

【SCI一区论文复】基于SLSPC系列的高阶PT-WPT无线电能传输系统研究(Matlab代码实现)内容概要:本文围绕“基于SLSPC系列的高阶PT-WPT无线电能传输系统研究”展开,重点复现SCI一区论文中的核心技术,通过Matlab代码实现高阶无线电能传输系统的建模与仿真。研究聚焦SLSPC拓扑结构在恒压-恒流(CV/CC)输出特性方面的优势,深入分析系统的传输效率、耦合特性、频率分裂现象及参数敏感性,并探讨其在高功率、长距离无线充电场景中的应用潜力。文中详细给出了系统数学建模、参数设计、仿真验证等关键步骤,旨在帮助读者掌握先进无线电能传输技术的核心原理与实现方法。; 适合人群:具备一定电力电子、自动控制理论基础,熟悉Matlab/Simulink仿真工具,从事无线电能传输、新能源充电技术等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入理解SLSPC型无线电能传输系统的恒压恒流输出机理;②掌握高阶WPT系统的建模、仿真与性能分析方法;③复现SCI一区论文成果,为后续科研创新提供技术基础和代码参考;④应用于无线充电、电动汽车、植入式医疗设备等领域的系统设计与优化。; 阅读建议:建议读者结合Matlab代码逐段分析系统模型构建过程,重点关注谐振参数设计、传输特性仿真及效率优化策略,同时可拓展研究不同耦合条件下的系统行为,以深化对高阶WPT系统动态特性的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值