# 55. 虚拟游戏理财

55 55-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
const lines = [];
rl.on('line', function(line) {
    lines.push(line);
});
rl.on('close', () => {
    const [m, N, X] = lines[0].split(' ').map(Number);
    const returns = lines[1].split(' ').map(Number);
    const risks = lines[2].split(' ').map(Number);
    const maxInvestments = lines[3].split(' ').map(Number);

    let maxReturn = 0;
    let bestInvestments = [];
    for(let i=0; i<m; i++) {
        if (risks[i] <=X) {
            const investmentForI = Math.min(N, maxInvestments[i]);
            const currentReturn = investmentForI * returns[i];
            if (currentReturn > maxReturn) {
                maxReturn = currentReturn;
                bestInvestments = new Array(m).fill(0);
                bestInvestments[i] = investmentForI;
            }
        }
        for(let j=i+1; j<m; j++) {
            if (risk[i] + risk[j] <= X) {
                let investmentForI, investmentForJ;
                if (returns[i] > returns[j]) {
                    investmentForI = Math.min(N, maxInvestments[i]);
                    investmentForJ = Math.min(N - investmentForI, maxInvestments[j]);
                } else {
                    investmentForJ = Math.min(N, maxInvestments[j]);
                    investmentForI = Math.min(N - investmentForJ, maxInvestments[i]);
                }
                const currentReturn = investmentForI * returns[i] + investmentForJ * returns[j];
                if (currentReturn > maxReturn) {
                    maxReturn = currentReturn;
                    bestInvestments = new Array(m).fill(0);
                    bestInvestments[i] = investmentForI;
                    bestInvestments[j] = investmentForJ;
                }
            }
        }
    }
    console.log(bestInvestments.join(' '));
})
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
38
39
40
41
42
43
44
45
46
47
48
49