Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 13703   Accepted: 3527

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

Source

Northeastern Europe 2005, Northern Subregion

这是一道潮湿的题……

二分测试答案,看用这个时间能不能把所有衣服都烘干。

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
int n;long long k;
long long a[mxn];
long long ans=;
long long calc(long long x){
int i,j;
long long cnt=;
for(i=;i<=n;i++){
if(a[i]>x){
long long xx = ceil((a[i]-x) * 1.0 / (k - ) );
cnt+=xx;
}
}
return cnt;
}
int main(){
scanf("%d",&n);
int i,j;
long long mxt=;
for(i=;i<=n;i++)
scanf("%lld",&a[i]),mxt=max(mxt,a[i]);
scanf("%lld",&k);
if(k==){
printf("%lld\n",mxt);
return ;
}
ans=;
long long l=,r=mxt;
while(l<=r){
long long mid=(l+r)/;
long long res=calc(mid);
if(res<=mid){
ans=mid;
r=mid-;
}
else l=mid+;
}
printf("%lld\n",ans);
return ;
}

POJ3104 Drying的更多相关文章

  1. POJ3104 Drying(二分查找)

    POJ3104 Drying 这个题由于题目数据比较大(1 ≤ ai ≤ 109),采用贪心的话肯定会超时,自然就会想到用二分. 设C(x)为true时表示所用时间为X时,可以把所有的衣服都烘干或者自 ...

  2. POj3104 Drying(二分)

    Drying Time Limit: 2000MS Memory Limit: 65536K Description It is very hard to wash and especially to ...

  3. poj3104 Drying(二分最大化最小值 好题)

    https://vjudge.net/problem/POJ-3104 一开始思路不对,一直在想怎么贪心,或者套优先队列.. 其实是用二分法.感觉二分法求最值很常用啊,稍微有点思路的二分就是先推出公式 ...

  4. POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15604   Accepted: 3976 Descripti ...

  5. POJ3104 Drying —— 二分

    题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  6. POj-3104 Drying 二分+贪心

    题目大意:有n件湿的衣服,每件衣服都有相应的湿度,每分钟每件衣服的湿度减1(除了在烘干机里的衣服),现在有一个烘干机,烘干机一分钟可以让一件衣服的湿度降低k,问至少要花多少分钟才能使每件衣服的湿度为0 ...

  7. Drying poj3104(二分)

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7916   Accepted: 2006 Descriptio ...

  8. Drying [POJ3104] [二分答案]

    背景 每件衣服都有一定单位水分,在不适用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台烘干机,每台烘干机同时只能烘干1件衣服,请问要 ...

  9. 【POJ - 3104 】Drying(二分)

    Drying 直接上中文 Descriptions 每件衣服都有一定单位水分,在不使用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台 ...

随机推荐

  1. 随机数生成器java实现

    /** 设计一个随机数生成器,可以产生给定平均概率的随机证书序列. 即输入一个概率比如:0.9 然后输入要求的概率样本个数比如:1000 输出一个接近所输入的0.9的概率数(要求样本数越大越接近输入的 ...

  2. 2018.10.30 NOIp模拟赛T2 数字对

    [题目描述] 小 H 是个善于思考的学生,现在她又在思考一个有关序列的问题.        她的面前浮现出一个长度为 n 的序列{ai},她想找出一段区间[L, R](1 <= L <= ...

  3. 二十五、MySQL 索引

    MySQL 索引 MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果合理的设计且使用索引的MySQL是一辆兰博基尼的话,那么没有设计和使用索 ...

  4. vmware 开机自动启动

    vmware开机自动启动, 可以使用vmrun命令. 1. 首先在“我的电脑”-“属性”-“高级”-“环境变量”-“PATH”中添加vmware路径,如:C:\Program Files (x86)\ ...

  5. 引用 Reference

    在Java中,判断一个对象是否 "存活" ,都和引用有关,当一个对象没有任何的引用指向它,我们可以认为这个对象可以被GC了. 引用如何定义?Object obj = new Obj ...

  6. Service IntentService区别 (面试)

    依然记得自己当初没有真正的工作经验的时候的日子,满北京跑,没有人要.妈的,现在就想问,还有谁!想想真解气.不提了. 曾经有个面试官问我service 和IntentService的区别.当时自己模模糊 ...

  7. Django 三—— Form组件

    内容概要: 1.Django Form如何自定义验证字段 2.Django Form如何动态的显示数据库中新插入的数据 3.Tyrion Django的Form(用于验证用户请求合法性的一个组件) D ...

  8. RNNs在股票价格预测的应用

    RNNs在股票价格预测的应用 前言 RNN和LSTMs在时态数据上表现特别好,这就是为什么他们在语音识别上是有效的.我们通过前25天的开高收低价格,去预测下一时刻的前收盘价.每个时间序列通过一个高斯分 ...

  9. C#实现eval 进行四则运算(有码)

    在JavaScript中实现四则运算很简单,只需要调用eval函数就行了,但是不知道什么原因万能的.NET却没有封装这个函数~ 在这里为大家封装了一个C#版本的eval函数,具体的设计参考了<大 ...

  10. 59、小米电视安装apk(无u盘操作)

    第一步 打开电视或者盒子,找到应用商店 第二步 打开应用商店 第三步.打开应用商店后,找到用户,别切换到快捷安装 第四步.记住地址,使用在同一网络下的电脑打开此网页 第五步.页面效果如图 第六步.找到 ...