# 19. 机器人仓库搬砖

19 19-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
function computed(bricks, hours) {
    if (bricks.length > 8) {
        return -1;
    }
    let left = -1;
    let right = Math.max(...bricks);
    while(left < right) {
        let mid = Math.floor((left + right)/2);
        let total_time = 0;
        for(let i=0; i<bricks.length; i++) {
            total_time += Math.ceil(bricks[i]/mid);
        }
        if(total_time > hours) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    let sum = 0;
    for(let i=0; i<bricks.length; i++) {
        sum += Math.ceil(bricks[i]/left);
    }
    if(sum > hours) {
        return -1;
    }
    return left;
}
rl.on('line', function(str)) {
    const bricks = input.split(' ').map(Number);
    console.log(computed(bricks, 8));
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37