Drying
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7959   Accepted: 2014

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
 
题目有个说的不是很清楚的地方当使用烘干机时是不减一的
二分时间即可
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue> using namespace std; #define maxn 100005 typedef long long ll; int n,k;
int a[maxn]; bool judge(ll x) { ll sum = ;
for(int i = ; i <= n; ++i) {
if(a[i] - x <= ) continue;
if(k == ) {
if(sum < a[i]) sum = a[i];
} else {
sum += (a[i] - x) / (k - ) + ((a[i] - x) % (k - ) > );
}
} return sum <= x;
} void solve() {
ll l = ,r = ; for(int i = ; i <= n; ++i) {
r += a[i];
} while(l < r) {
ll mid = (l + r) >> ; if(judge(mid)) {
r = mid;
} else {
l = mid + ;
}
} cout << l << endl;
} int main() { // freopen("sw.in","r",stdin); scanf("%d",&n);
for(int i = ; i <= n; ++i) {
scanf("%d",&a[i]);
}
scanf("%d",&k); sort(a + ,a + n + ); solve(); return ;
}

POJ 3104的更多相关文章

  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(二分答案)

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

  4. poj 3104 Drying(二分查找)

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

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

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

  6. Divide and conquer:Drying(POJ 3104)

    烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...

  7. poj 3104 Drying(二分搜索之最大化最小值)

    Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...

  8. poj 3104 二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12568   Accepted: 3243 Descripti ...

  9. Drying POJ - 3104

    It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...

随机推荐

  1. Windows Phone 7 中拷贝文件到独立存储

    private void CopyToIsolatedStorage(){    using (IsolatedStorageFile storage = IsolatedStorageFile.Ge ...

  2. 使用 Time Machine 恢复 .ssh等隐藏文件夹

    重装MAC系统后,要恢复.ssh等文件夹内容,而其在“Finder”中又是默认隐藏的,这时我们可以先在“Finder”中使用“前往文件夹功能…”进入指定文件夹,然后再进入“Time Machine”进 ...

  3. Fedora 20 创建桌面快捷方式

    创建desktop文件 sudo touch /usr/share/applications/sublime.desktop 添加内容 [Desktop Entry] Encoding=UTF-8 N ...

  4. WCF 服务与终结点(四)

    服务 服务是一组公开功能的集合. 服务内部包含了如语言.技术.版本与框架等概念,服务之间的交互只允许使用规定的通信模式 外界客户端并不知道服务内部的实现细节,所以WCF服务通常通过元数据的方式描述可用 ...

  5. visual studio中创建单元测试

    1 打开  工具--自定义 2 选择 上下文菜单--编辑器上下文菜单|代码窗口 3 在这里我们可以看到“创建单元测试”这个菜单了,将它移到运行测试菜单下面 4 关闭VS并重启 重启后再对着类名,点击右 ...

  6. centOS 一键php环境安装-php博弈

    我是方少,闲着没事,感觉每次编译安装,再修改php,mysql,redis,nginx配置文件觉得把大好的青春时间都浪费掉了.如是想着,怎样一键安装 php环境和相关配置.于是拜读了一下lnmp的一键 ...

  7. 1100. Mars Numbers (20)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  8. Excel REPT函数使用

    需要制作1K大小的数据 使用Excel REPT函数可以迅速制造 Excel REPT 函数 =REPT(1,1024) 结果直接黏贴进txt文件,注意删除尾空格.

  9. linux c 验证登录密码

    #define _XOPEN_SOURCE #include <stdio.h> #include <unistd.h> int main(int argc, char *ar ...

  10. Jquer Ajax xmlhttp请求成功了,为什么一直在error函数里面

    转载自http://www.cnblogs.com/sky_Great/archive/2013/01/18/2866861.html 并进行整理: 今天遇到了一个极其奇怪的问题,用各种工具检查都能看 ...