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

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



————————————————————————————————————
题目的意思是给出n条衣服,每条衣服带水ai,单位时间每条会自然风干减少1单位水,有一台烘干机,单位时间可以帮助减少k单位水(不属于自然风干了),求全部弄干需要多少时间
思路:二分+验证 二分时间,算出能否在该时间烘干,设当前为x,每件衣服应该自然减少x单位,烘干机可视为减少(k-1)单位,然后去检查能否完成
注意:k可能等于1,可能会出现/0RE情况 特判即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long LL a[100005],k;
int n; bool ok(LL x)
{
LL ans=0;
for(int i=0; i<n; i++)
{
LL xx=max((LL)0,a[i]-x);
ans=ans+(xx+k-1)/k;
}
if(ans<=x)
return 1;
return 0;
} int main()
{
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
{
scanf("%lld",&a[i]);
}
scanf("%lld",&k);
if(k==1)
{
LL ans =-1;
for(int i=0; i<n; i++)
ans=max(ans,a[i]);
printf("%lld\n",ans);
}
else
{
k--;
LL l=0,r=1e9;
LL ans=-1;
while(l<=r)
{
LL mid=(l+r)/2;
if(ok(mid))
{
r=mid-1;
ans=mid;
}
else
l=mid+1;
}
printf("%lld\n",ans);
}
} return 0;
}

POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏的更多相关文章

  1. HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏

    Qin Shi Huang's National Road System                                                                 ...

  2. ZOJ3703 Happy Programming Contest 2017-04-06 23:33 61人阅读 评论(0) 收藏

    Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University P ...

  3. 你所不知道的C和C++运行库 标签: vc 2017-05-26 10:33 41人阅读 评论(0) 收藏

    在使用vs2013调用vc2005编译出的dll时出现错误,遂将源程序用vs2013编译出dll,再用vs2013调用错误消失,不解.寻找原因时有人说"VC库版本不一样",故查找C ...

  4. 排序练习——找出前m大的数字 分类: 排序 2015-06-08 09:33 21人阅读 评论(0) 收藏

    排序练习--找出前m大的数字 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给定n个数字,找出前m大的数字.   输入  多组输 ...

  5. POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25225 ...

  6. 周赛-Colored Sticks 分类: 比赛 2015-08-02 09:33 7人阅读 评论(0) 收藏

    Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 32423 Accepted: 8556 Desc ...

  7. ASIHTTPRequest异步请求 分类: ios技术 2015-03-01 09:33 48人阅读 评论(0) 收藏

    我们运行程序,如果网速很慢,查询的时候会一直黑屏,直到请求结束画面才出现,这样用户体验很不好.因此同步请求一般只是在某个子线 程中使用,而不在主线程中使用.异步请求的用户体验要比同步请求好,因此一般情 ...

  8. JVM调优基础 分类: B1_JAVA 2015-03-14 09:33 250人阅读 评论(0) 收藏

    一.JVM调优基本流程 1.划分应用程序的系统需求优先级 2.选择JVM部署模式:单JVM.多JVM 3.选择JVM运行模式 4.调优应用程序内存使用 5.调优应用程序延迟 6.调优应用程序吞吐量 二 ...

  9. 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏

    May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...

随机推荐

  1. (4)shiro多个realm

    shiro支持多个realm,当设置多个realm的时候,shiro的认证和授权的步骤是怎样的呢. 多个realm认证原理: 发现需要在执行认证的时候,需要策略来处理多个realm存在的情况.默认实现 ...

  2. 回调(CallBack)

    又名钩子函数(C语言里Hook) 不知道如何实现,可以写个回调, 相当于提供个钩子,让别人来挂东西,来实现. 其实就是用多态,实现了分离 . package cn.bjsxt.oop.callback ...

  3. PHP与apache配置

    在apache 的安装路径中找到 \conf\httpd.conf文件 在 LoadModule最后面添加如下代码: PHPIniDir "D:\PHP"LoadModule ph ...

  4. idea下maven项目打包

    近使用idea运行maven需要打包上传tomcat服务器.但是网上一直零零碎碎的....自己记录一下.以防后面忘记 1.idea中.file →Project Structure(快捷键Ctrl+S ...

  5. linux下挂载磁盘操作

      重启服务器,查看是否挂载上去了 CentOS云服务器数据盘分区和格式化 腾迅云: http://wiki.qcloud.com/wiki/CentOS%E4%BA%91%E6%9C%8D%E5%8 ...

  6. 工作流和过程自动化框架 Camunda BPM

    Camunda BPM 是一个灵活的工作流和过程自动化框架,它的核心是一个在Java虚拟机内部运行的原生BPMN 2.0流程引擎,因此它可以嵌入到任何Java应用程序或运行时容器中.Camunda B ...

  7. IIS7配置下载apk以及目录浏览

    IIS7为了增加安全性,如果需要禁止目录浏览.只需要按下面的步骤执行就可以 1.选择站点:2.选择功能视图:3.选择IIS下面的目录浏览:4.在右上角的操作中选择“打开功能”:5.选择右边的禁用. 今 ...

  8. Android模拟器内安装应用

    一.通过apk安装器安装应用 1.下载apk安装器(网上随便搜一个就可以) 2.下载要测试的应用的apk,我这里下载的是微信的apk 3.打开apk安装器,点击右上角的Devices选择要安装到的设备 ...

  9. 强关联二维材料1T—TaS2晶体

    我校物理系张远波教授课题组通过一种新的实验方法——可控电荷插层,实现了对强关联二维材料1T—TaS2晶体相变的全面研究.1月26日,相关研究论文Gate-tunable phase transitio ...

  10. nyoj528-找球号(三) 【位运算】

    http://acm.nyist.net/JudgeOnline/problem.php?pid=528 找球号(三) 时间限制:2000 ms  |  内存限制:3000 KB 难度:2   描述 ...