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 ...
随机推荐
- mmtests使用简介
1.简介 mmtests是一个可配置的测试套件,可以被MM开发者用来进行一个常规测试.理想情况下,它可以与LTP,xfstests等测试工具结合起来实现自动化测试. 2.软件组织 run-mmtest ...
- sql server 2005 外围应用配置器
想要实现sql server 2005 远程连接数据库,我们必需要用到sql05上自带的外围配置器,以下是对它的一些配置上的介绍: 首先我们要打开sql05外围配置器,例如以下图: 打开后,我们如今就 ...
- 贴一个CMemDC 代码,这东西真不错噢,短小精悍,可谓极品
罗索客 发布于 2006-11-28 21:53 点击:3941次 来自: 原文: http://yuantao82.spaces.live.com/Blog/cns!8FC0A772D812A22 ...
- VC 获取指定文件夹路径的方法小结
VC获取指定文件夹路径 flyfish 2010-3-5 一 使用Shell函数 1 获取应用程序的安装路径 TCHAR buf[_MAX_PATH];SHGetSpecialFolderPath( ...
- 手把手教你_android自己主动化实践方案选型
接到一个android自己主动化的任务,看了看手中的家伙:ranorex,appium,uiautomator 当然先捡商用的试试,简单呀,能够录制回放,只是不是抱特别大的期望,这个爷比較娇气,要是a ...
- Java核心技术-高级特性(2)- SoftReference, WeakReference and PhantomReference
Java.lang.ref 是 Java 类库中比较特殊的一个包,它提供了与 Java 垃圾回收器密切相关的引用类.这些引用类对象可以指向其它对象,但它们不同于一般的引用,因为它们的存在并不防碍 Ja ...
- oc深坑測试题及其答案
一.选择题(共80题,每题1分) 1. 不会立马使引用计数器改变的是: 答案:(C) A.release B.alloc C.autorelease D.retain 2. 在OC中类的接口声 ...
- java学习笔记09--反射机制
java学习笔记09--反射机制 什么是反射: 反射是java语言的一个特性,它允许程序在运行时来进行自我检查并且对内部的成员进行操作.例如它允许一个java的类获取他所有的成员变量和方法并且显示出来 ...
- poj 2411 Mondriaan's Dream dp
一个比较简单的状压dp,记录下每个点的状态即可. #include <iostream> #include <cstdio> #include <cstring> ...
- C#向并口设备发送指令以获取并口设备的状态
using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; usi ...