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++虐恋:MBCS安装失败导致的四天误工

    情况描述:接收远程队友的C++代码,基于vc120工具集(VS2013),而我的机器上是VS2015,需要安装VS2013(只选MFC,除主程序与MFC外其余的组件全部卸掉).然后开始编译,提示 MS ...

  2. 使用 CocoStudio UI 编辑器实现《乱斗堂》设置界面

    由于是引用别人的,所以直接贴上地址了.http://www.cocoachina.com/bbs/read.php?tid=164820&fpage=7 1 游戏中必不可少的 UI 元素    ...

  3. oc常见误区

    1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...

  4. MySQL高可用之MHA (转)

    MySQL高可用之MHA MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案.MHA能够在30秒内实现故障切换,并能在故障 ...

  5. 双机倒换(NewStartHA,SKYbility,hacmp,hp unix双机)

    1.Suse linux  (NewStartHA):                # cli cli:~>service-migrate Select service to migrate: ...

  6. linux系统启动流程

    BIOS: (Basic Input Output System)基本输入输出系统,一般保存在主板上的BIOS芯片中 BIOS是计算机启动时运行的第一个程序,负责检查硬件并且查找可启动设备. 可启动设 ...

  7. Silverlight自动根据屏幕分辨率进行布局

    xaml: <UserControl x:Class="SLCenterLayout.MainPage" xmlns="http://schemas.microso ...

  8. webstorm 10.0.4 注册码

    激活码: UserName:William ===== LICENSE BEGIN ===== 45550-12042010 00001SzFN0n1bPII7FnAxnt0DDOPJA INauvJ ...

  9. selenium+python 浏览器标签页跳转 switch_to_window

    浏览器页面跳转方法记录: from selenium import webdriver import time browser = webdriver.Chrome() first_url='http ...

  10. Java读取本地文件进行unicode解码

    工具使用: package test.opservice; import eh.util.MapValueUtil; import java.io.BufferedReader; import jav ...