2013
11-12

# Drying

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.

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 a single integer — the minimal possible number of minutes required to dry all clothes.

sample input #1
3
2 3 9
5

sample input #2
3
2 3 6
5

sample output #1
3

sample output #2
2

//* @author: 82638882@163.com
import java.io.*;
public class Main
{
static int[] p;
static int a,k;
public static void main(String[] args) throws IOException
{
p=new int[a];
long total=0;
for(int i=0;i< a;i++){
p[i]=Integer.parseInt(ss[i]);
total+=p[i];
}

int v=k+a-1;
long min=total/v;
long high=total;
while(high>min)
{
long mid=(high+min)/2;
if(f(mid)) high=mid;
else min=mid+1;
}
System.out.println(min);
}
static boolean f(long t)
{
long u=t;
for(int i=0;i< a;i++)
{
if(p[i]<=t)continue;
long sy=p[i]-t;
u-=sy/(k-1);
if(sy%(k-1)!=0)
u--;
}
if(u< 0) return false;
else return true;
}
}

1. 有两个重复的话结果是正确的，但解法不够严谨，后面重复的覆盖掉前面的，由于题目数据限制也比较严，所以能提交通过。已更新算法

2. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false

4. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;