2 shunfurh shunfurh 于 2017.01.03 15:07 提问

Drying

Description

It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at a time.

Jane wants to perform drying in the minimal possible time. She asked you to write a program that will calculate the minimal time for a given set of clothes.

There are n clothes Jane has just washed. Each of them took ai water during washing. Every minute the amount of water contained in each thing decreases by one (of course, only if the thing is not completely dry yet). When amount of water contained becomes zero the cloth becomes dry and is ready to be packed.

Every minute Jane can select one thing to dry on the radiator. The radiator is very hot, so the amount of water in this thing decreases by k this minute (but not less than zero — if the thing contains less than k water, the resulting amount of water will be zero).

The task is to minimize the total time of drying by means of using the radiator effectively. The drying process ends when all the clothes are dry.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000). The second line contains ai separated by spaces (1 ≤ ai ≤ 109). The third line contains k (1 ≤ k ≤ 109).

Output

Output a single integer — the minimal possible number of minutes required to dry all clothes.

Sample Input

sample input #1
3
2 3 9
5

sample input #2
3
2 3 6
5
Sample Output

sample output #1
3

sample output #2
2

1个回答

devmiao
devmiao   Ds   Rxr 2017.01.03 18:39
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
POJ 3104 Drying 二分
来源:http://poj.org/problem?id=3104 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水。每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发。问最少需要多少时间能烘干所有的衣服。 思路:首先可以想到二分枚举答案。枚举一个mid值时,若一件衣服的水量大于mid,则一件衣服的最短时间是烘干一段时间,在自己蒸发一段时间。
poj 3104 Drying 二分答案
二分答案
POJ 3104 Drying-二分答案
题意:有n件衣服需要晒干,每件有a[i]的水分,干燥有两种方式:1.自然风干,每分钟水分-1;2.用机器,每分钟只能用于一件衣服,且每件衣服水分-k。求弄干这n件衣服需要的最少的时间。 分析: 答案肯定在0~max(a[i])内,所以二分这个区间。然后检验在mid的时间内能否把n件衣服干燥,这个判断函数的核心是计算式:tot+=ceil(double(a[i]-mid)/double(k-1)
POJ - 3104 Drying 二分 + 贪心
题目大意:有n件湿的衣服,每件衣服都有相应的湿度,每分钟每件衣服的湿度减1(除了在烘干机里的衣服),现在有一个烘干机,烘干机一分钟可以让一件衣服的湿度降低k,问至少要花多少分钟才能使每件衣服的湿度为0解题思路:贪心的话,每分钟都要使用到烘干机。 枚举时间,如果湿度小于等于时间的话,就不用考虑了,在枚举时间内肯定会干的 如果湿度大于枚举时间的话,就要考虑一下了,该衣服要在给定时间内湿度变为零的话就
poj 3104 Drying 二分+基本数学
传送门:poj 3104 Drying题目大意有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水。每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发。问最少需要多少时间能烘干所有的衣服。解题思路要知道如果想要晾干衣服的话,最好的方法就是使用机器冲干x1秒,然后等待风干x2秒。我们来二分答案mid,表示能在mid秒钟晒干。 机器烘干需要x1秒钟,自然烘干需
二分法--案列(烘干衣服 poj3104)
Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18921   Accepted: 4742 Description It is very hard to wash and especially to dry clothes in winter. Bu
POJ: Drying(二分、值最小化)
题目链接:POJ - 3104 题意:有n件湿衣服,分别给出其含水量。若衣服放在空气中,每分钟含水量会减少1;若把衣服放进烘干器里面则含水量每分钟会减少k,当衣服含水量为0时说明衣服已经干了,现在问要至少经过多少分钟能使所有的衣服都干了 思路:设每件衣服要mid" role="presentation" style="position: relative;">midmidmid分钟干,其
POJ3104-Drying
首先很难想到用二分,其次判断时要用long long.... #include #include using namespace std; const int maxn = 10e5+10; const int inf = 10e9+10; int a[maxn]; bool judge(int mid, int n, int k) { long long minute =
POJ 3104 Drying(二分搜索,最大化最小值)
Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11464   Accepted: 2967 Description It is very hard to wash and especially to dry clothes in winter.
Drying<二分,思维题>
Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16728   Accepted: 4238 Description It is very hard to wash and especially to dry clothes in winter.