Drying
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9440   Accepted: 2407

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
题目大意:有n件衣服,每件衣服有一定的水量,使衣服干有两种方法:1、水分蒸发,每分钟蒸发掉一滴水 2、用烘干机烘干,每分钟烘干掉k滴水。题目要输出的是是所有衣服变干的最小时间。

详见代码。
 #include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define ll long long int main ()
{
int n;
ll a[+];
ll tmax;
while (~scanf("%d",&n))
{
tmax=;
for (int i=; i<n; i++)
{
scanf("%lld",&a[i]);
if (a[i]>tmax)
tmax=a[i];
}
ll k;
scanf("%lld",&k);
if (k==)
{
printf ("%lld",tmax);
continue;
}
ll l=,r=tmax,mid,ans=;
while (r>=l)
{
ll sum=;
mid=(l+r)/;
for (int i=;i<n;i++)
{
if(a[i]>mid)
{
ll s=ceil((a[i]-mid)*1.0/(k-));
sum+=s;
}
}
if (sum>mid)
l=mid+;
else
r=mid-,ans=mid;
}
printf ("%lld\n",ans);
}
return ;
}

 

poj 3104 Drying(二分查找)的更多相关文章

  1. POJ 3104 Drying(二分答案)

    题目链接:http://poj.org/problem?id=3104                                                                  ...

  2. POJ 3104 Drying 二分

    http://poj.org/problem?id=3104 题目大意: 有n件衣服,每件有ai的水,自然风干每分钟少1,而烘干每分钟少k.求所有弄干的最短时间. 思路: 注意烘干时候没有自然风干. ...

  3. POJ 3104 Drying [二分 有坑点 好题]

    传送门 表示又是神题一道 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9327   Accepted: 23 ...

  4. POJ 3104 Drying (二分+精度)

    题目链接:click here~~ [题目大意]: 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次能够烘一件衣服,每分钟能够烘掉k单位水. 每件衣服没分钟能够自己主动蒸发掉一单位水, 用烘干 ...

  5. poj 2452(RMQ+二分查找)

    题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j ...

  6. POJ 3104 Drying(二分答案)

    [题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...

  7. POJ 3104 Drying(二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22163   Accepted: 5611 Descripti ...

  8. POJ 3104 Drying (经典)【二分答案】

    <题目链接> 题目大意: 有一些衣服,每件衣服有一定水量,有一个烘干机,每次可以烘一件衣服,每分钟可以烘掉k滴水.每件衣服没分钟可以自动蒸发掉一滴水,用烘干机烘衣服时不蒸发.问最少需要多少 ...

  9. poj 3122 (二分查找)

    链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

随机推荐

  1. Sqoop使用笔记(转载)

    Sqoop是Apache顶级项目,主要用来在Hadoop和关系数据库中传递数据.通过sqoop,可以方便的将数据从关系数据库导入到HDFS,或将数据从HDFS导出到关系数据库. 关于Sqoop 官网S ...

  2. xpath教程一---简单的标签搜索

    工具 Python3版本 lxml库[优点是解析快] HTML代码块[从网络中获取或者自己杜撰一个] requests[推荐安装,从网页上获取网页代码练手,再好不过了] 讲解 网页代码都是成对的标签, ...

  3. name(实例化类名).hbm.xml文件案例

    [html] view plain copy print? <span xmlns="http://www.w3.org/1999/xhtml"><?xml ve ...

  4. Android studio出现Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"的解决办法

    最近更新了一下Android Studio(下文简写成AS),然后打开工程发现出现Error:Unable to tunnel through proxy. Proxy returns "H ...

  5. Swift & Unicode

    Swift & Unicode emoji let == const https://www.runoob.com/swift/swift-basic-syntax.html

  6. 第43天:事件对象event

    一.事件对象事件:onmouseover. onmouseout. onclickevent //事件的对象 兼容写法:var event = event || window.event; event ...

  7. WPF DataGrid的使用

    构造数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  8. 利用FluidMoveBehavior制作出手机通讯录平滑的效果

    最近学习Blend,原来Blend制作动画等效果非常棒.下面演示一下FluidMoveBehavior应用,利用Blend中行为中的FluidMoveBehavior制作出手机通讯录平滑的效果 1.在 ...

  9. Socket_FTP

    1. md5加密回顾: import hashlib m=hashlib.md5() #创建md5对象 m.update(b'abcd') #生成加密串 m.update(b'efg') print( ...

  10. POJ3335:Rotating Scoreboard——题解

    http://poj.org/problem?id=3335 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— 看了两个小时的资料, ...