blob: e52994e66e691b013a6a8a0fdc29cf24159821fd (
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
|
#!/bin/sh
#
# See ../README.md
#
#
# Run as: bash ch-2.sh < input-file
#
set -f
while read -a heights
do ((max_height = 0))
for ((i = 0; i < ${#heights[@]}; i ++))
do if ((max_height < ${heights[$i]}))
then ((max_height = ${heights[$i]}))
fi
done
((max_area = 0))
for ((h = 1; h <= max_height; h ++))
do ((max = 0))
((cur = 0))
for ((i = 0; i < ${#heights[@]}; i ++))
do if ((${heights[$i]} >= h))
then ((cur ++))
else if ((cur > max))
then ((max = cur))
fi
((cur = 0))
fi
done
if ((cur > max))
then ((max = cur))
fi
((area = max * h))
if ((max_area < area))
then ((max_area = area))
fi
done
echo $max_area
done
|