POJ 3104 Drying
POJ 3104 Drying
POJ 3104 Drying
题目链接
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 ≤ 1e9). The third line contains k (1 ≤ k ≤ 1e9).
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
简单二分,AC代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n;
ll k,a[N];
bool check(ll x){
ll cnt=0;
for(int i=1;i<=n;i++){
if(a[i]<=x) continue;
else{
cnt+=(a[i]-x+k-2)/(k-1);
}
}
return (cnt<=x);
}
int main() {
scanf("%d%",&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
scanf("%lld",&k);
sort(a+1,a+1+n);
if(k==1){
printf("%lld",a[n]);
return 0;
}
ll l=0,r=1e18;
while(l<=r){
ll mid=l+r>>1;
if(check(mid)) r=mid-1;
else l=mid+1;
}
printf("%lld",l);
return 0;
}
- 如何选择移动电源
- Thumbs.db文件是什么
- 体感技术
- ISP是什么?
- CPU和显卡最新天梯图
- 电脑音箱选购四步曲
- 安卓笑了:为什么说苹果iOS是伪后台?
- # 标题Windows最强神器,WIN+R的最骚使用方法!
- 腾讯新闻中心首页改版啦
- 手机wifi已连接但无法访问互联网_我们的手机WiFi出现“已连接但无法上网”时咋办?...
- 笔记本桌面窗口管理器占用内存过高怎么办?
- DELL戴尔笔记本电脑灵越Inspiron 14 5410&5418原厂Win10系统恢复原装OEM出厂状态系统
- Appium: Windows系统桌面应用自动化测试(一) 【环境搭建】
- ipadwindows文件共享(Samba)
- 谷歌云DD装系统
- 操作系统精讲(0) | 操作系统详细简介
- 华为k662c的虚拟服务器,华为k662c路由器怎么设置 | 华为k662c路由器设置_什么值得买...