-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrect.js
65 lines (58 loc) · 1.28 KB
/
rect.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var inp = 3;
var N, M;
var A = [], B = [];
rl.on('line', (input)=>{
if(inp===3) {
N = input.split(' ')[0];
M = input.split(' ')[1];
inp--;
} else if(inp===2) {
let t_A = input.split(' ');
t_A.forEach(element => {
A.push(element);
});
inp--;
} else if(inp===1) {
let t_B = input.split(' ');
t_B.forEach(element => {
B.push(element);
});
main();
rl.close();
}
});
function main() {
var C = [];
for(var i=0; i<N; i++){
let set = [];
for(var j=0; j<M; j++)
set.push(A[i] * B[j]);
C.push(set);
}
var sums = [];
for(let s_X=0; s_X<N; s_X++){
for(let s_Y=0; s_Y<M; s_Y++){
for(let e_X=s_X; e_X<N; e_X++){
for(let e_Y=s_Y; e_Y<N; e_Y++){
// Sum the Rectangle
var sum=0;
for(let i=s_X; i<=e_X; i++){
for(let j=s_Y; j<=e_Y; j++){
sum+=C[i][j];
}
}
sums.push(sum);
}
}
}
}
let max = sums[0];
for(let m=0; m<sums.length; m++)
if(sums[m]>max) max = sums[m];
console.log(max);
}