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. C++向main函数传递参数的方法(实例已上传至github)

    通常情况下,我们定义的main函数都只有空形参列表: int main(){...} 然而,有时我们确实需要给mian传递实参,一种常见的情况是用户设置一组选项来确定函数所要执行的操作.例如,假定ma ...

  2. newsstand杂志阅读应用源码ipad版

    一款newsstand iPad杂志阅读应用源码(newsstand在线下载/动态显示等)可以支持在线下载/动态显示等  ,也是一款newsstand iPad杂志阅读应用源码.运行之后,会在iPad ...

  3. 【风马一族_xml】xml的基本讲解笔记

    xml是如何保存数据的 在xml语言中,它允许用户自定义标签.每个标签用于描述一段数据; 一个标签可以分为开始标签和结束标签,在开始标签和结束标签之间又可以嵌套其它标签,利用标签间的嵌套其它标签,利用 ...

  4. linux下别名alias的设置

    我有一个常用目录/volumes/mac/www’,每次都要输入这么长的路径,麻烦,所以有了以下配置 1.vi ~/.bash_profile 2.按住shift + i进入编辑状态 3.插入 ali ...

  5. silverlight 用户浏览器未安装SL插件问题

    1.在Silverlight启动页面 <%@ Page Language="C#" AutoEventWireup="true" %> <!D ...

  6. AngularJS(12)-BootStrap集成

    AngularJS 的首选样式表是 Bootstrap, Bootstrap 是目前最受欢迎的前端框架. <!DOCTYPE html> <html lang="en&qu ...

  7. jdbc 连接 mysql 获取 数据集 条数

    package nona; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; im ...

  8. TIME_WAIT引起Cannot assign requested address报错

    1.  问题描述 有时候用redis客户端(php或者java客户端)连接Redis服务器,报错:"Cannot assign requested address." 原因是客户端 ...

  9. oracle 11g rac 修改字符集

    系统版本: Oracle Linux Server release 5.7 数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.3 ...

  10. MySQL通过Binlog恢复删除的表

    查看log-bin是否开启:mysql> show variables like '%log%bin%';+---------------------------------+-------+| ...