# 21. 寻找最富裕的小家庭
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let inputs = [];
rl.on('line', function(str)) {
inputs.push(str);
}
rl.on('close', function() {
const N = parseInt(inputs[0]);
const wealth = input[1].split(' ').map(Number);
wealth.unshift(0);
const familyWealth = [...wealth];
let maxWealth = wealth[1];
for(let i=2; i<N+1; i++) {
const [N1, N2] = input[i].split(' ').map(Number);
familyWealth[N1] += wealth[N2];
maxWealth = Math.max(maxWealth, familyWealth[N1]);
}
console.log(maxWealth);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24