```
/**
* @
author zoyao.
* @
create 2022/2/11
* @
param a 自然烘干每单位时间烘干湿度
* @
param b 机器烘干每单位时间烘干湿度
* @
param cloths 所有待烘干衣服
* @
return */
public double dry(int a, int b, int[] cloths) {
Arrays.sort(cloths);
long total =
Arrays.stream(cloths).sum();
double hourMin = cloths[cloths.length - 1];
//假设烘干时间在 cloths[i-1]至 cloths[i]之间
for (int i = 0; i < cloths.length; i++) {
int cloth = cloths[i];
//只计算所有湿度大于等于 cloths[i-1]的衣服
//自然烘干:a * (cloths.length - i) * hour
//机器烘干:b * hour
double hour = (double) total / (a * (cloths.length - i) + b);
total -= cloth;
//不满足上述假设条件
if (hour > cloth || (i > 0 && hour < cloths[i - 1])) {
continue;
}
if (hour < hourMin) {
hourMin = hour;
}
}
return hourMin;
}
```