blob: 757184d399ea3533c7c8d9e4d68595ee49dbedcc (
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
44
45
|
#!/usr/bin/ruby
#
# See ../README.md
#
#
# Run as: ruby ch-2.rb < input-file
#
ARGF . each_line do
|line|
heights = line . split . map do
|h|
h . to_i
end
max_height = heights . max
max_area = 0
for h in 1 .. max_height do
max = 0
cur = 0
heights . map do
|height|
if height >= h
cur += 1
else
if max < cur
max = cur
end
cur = 0
end
end
if max < cur
max = cur
end
area = max * h
if max_area < area
max_area = area
end
end
puts (max_area)
end
|