blob: 64b04898ad93dde418f3fbc1e8284ebcd331f575 (
plain)
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
|
#!/usr/local/bin/node
//
// See ../README.md
//
//
// Run as: node ch-2.js < input-file
//
require ('readline')
. createInterface ({input: process . stdin})
. on ('line', line => {
let heights = line . split (" ") . map (_ => +_)
let max_height = Math . max (... heights)
let max_area = 0
let i, h
for (h = 1; h <= max_height; h ++) {
let cur = 0
let max = 0
for (i = 0; i < heights . length; i ++) {
if (heights [i] >= h) {
cur ++
}
else {
if (max < cur) {
max = cur
}
cur = 0
}
}
if (max < cur) {
max = cur
}
let area = max * h
if (max_area < area) {
max_area = area
}
}
console . log (max_area)
})
|