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 ≤ 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
2 10
30 35 1 100
20 35 10 10
120
3 100
10 30 1000 1
5 10 1000 3
10 40 1000 100000
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;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Hot Days Codeforces Round #132 (Div. 2) D(贪婪)的更多相关文章
- Codeforces Round #132 (Div. 2)
A. Bicycle Chain 统计\(\frac{b_j}{a_i}\)最大值以及个数. B. Olympic Medal \(\frac{m_{out}=\pi (r_1^2-r_2^2)hp_ ...
- Educational Codeforces Round 132 (Rated for Div. 2)
Educational Codeforces Round 132 (Rated for Div. 2) A. Three Doors 简述 题意: 有三扇门(1~3), 其中两扇门后面有对应标号门的钥 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- Sublime Text3 + Golang搭建开发环境
Sublime Text3 + Golang搭建开发环境 http://blog.csdn.net/aqiang912/article/details/46775409 1.安装git 因为golan ...
- XP下的进程静音技术(遍历进程,遍历输入模块,遍历输入函数,找到函数并HOOK) good
很多浏览器有这种功能,实现原理都是一样.发声源基本都来自Flash,比如Flash游戏啦,视频播放器啦等等 而Flash的发声都是通过winmm.dll::waveOutWrite函数来完成,所以,我 ...
- c++ 类名和enum时重复时要在类名前加class::
c++ 类名和enum时重复时要在类名前加class:: 一些不好的习惯都是用小写,但又没有区分开token,看看代码再说,下面的代码是我在测试polymorphism时写的一部分,怎么也查不出,最后 ...
- 编程语言性能游戏排行榜,C/C++第一ATS第二JAVA第三
编程语言性能游戏排行榜,C/C++第一ATS第二JAVA第三 编程语言性能游戏排行榜,C/C++第一ATS第二JAVA第三
- iOS 5 故事板入门(3)
原文: http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-2 Segues 介绍 是时候在我们的故事板中加入更 ...
- 【老鸟学算法】包含 min函数的栈设计——java实现
要求: 1. 定义栈的数据结构,要求添加一个 min函数,能够得到栈的最小元素. 2. 要求函数 min.push 以及 pop 的时间复杂度都是 O(1). 这是考验“栈”数据结构设计.众所周知,栈 ...
- hdu 1665 That Nice Euler Circuit(欧拉定理)
输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分. 根据欧拉定理 v_num + f_num - e_num = 2可知 ...
- UVa 11371 - Number Theory for Newbies
題目:給你一個數字n.將裡面每位的數又一次組合形成a,b.使得a-b最大且是9的倍數. 分析:數論. 題目要求a,b和n的位數同样,不能有前導0. 定理1:交換一個數字中的某兩個位的數,形成的新數組和 ...
- C/C++中constkeyword
今天在做一个趋势笔试题的时候.才让我有了系统把constkeyword好好总结一下的冲动,由于这个关键词大大小小好多地方都出现过,出现频率很高,而每次仅仅是简短的把答案看了一下,没有真正将其整个使用方 ...
- oracle实现远程连接超简单;枚举与剪枝();PowerDesigner生成数据库代码注意里面的双引號,应该去掉
点击開始,查看netManager,点击面板的监听程序,默认仅仅有地址1且标记着localhost.新建一个地址,输入本机IP,又一次开启监听程序就可以 △△△ * △△ = △△△△ 某3位数乘以2 ...