<?php
function divideEtImpera($arr, $lo, $hi, &$min, &$max) {
if($lo == $hi) {
$min = $max = $arr[ $lo ];
} else {
$m = ($lo + $hi) >> 1;
divideEtImpera($arr, $lo, $m, $x, $a);
divideEtImpera($arr, $m + 1, $hi, $y, $b);
if($x < $y) $min = $x;
else
$min = $y;
if($a > $b) $max = $a;
else
$max = $b;
}
};
$arr = array(1,2,87,33,11,34,91,71);
divideEtImpera
($arr, 0, sizeof($arr) - 1, $min, $max);
echo"MIN = ". $min;
echo"\n";
echo"MAX = ". $max;
echo"\n";
?>
PD9waHAKICBmdW5jdGlvbiBkaXZpZGVFdEltcGVyYSgkYXJyLCAkbG8sICRoaSwgJiRtaW4sICYkbWF4KSB7CgogICAgICAgICAgIGlmKCRsbyA9PSAkaGkpIHsKCiAgICAgICAgICAgICAgJG1pbiA9ICRtYXggPSAkYXJyWyAkbG8gXTsKICAgICAgICAgICB9IGVsc2UgewoKICAgICAgICAgICAgICAkbSA9ICgkbG8gKyAkaGkpID4+IDE7CiAgICAgICAgICAgICAgZGl2aWRlRXRJbXBlcmEoJGFyciwgJGxvLCAkbSwgJHgsICRhKTsKICAgICAgICAgICAgICBkaXZpZGVFdEltcGVyYSgkYXJyLCAkbSArIDEsICRoaSwgJHksICRiKTsKICAgICAgICAgICAgICBpZigkeCA8ICR5KSAkbWluID0gJHg7CiAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgICAkbWluID0gJHk7CiAgICAgICAgICAgICAgaWYoJGEgPiAkYikgJG1heCA9ICRhOwogICAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICRtYXggPSAkYjsKICAgICAgICAgICB9CiAgfTsKCiAgJGFyciA9IGFycmF5KDEsMiw4NywzMywxMSwzNCw5MSw3MSk7CgogIGRpdmlkZUV0SW1wZXJhKCRhcnIsIDAsIHNpemVvZigkYXJyKSAtIDEsICRtaW4sICRtYXgpOwoKICBlY2hvIk1JTiA9ICIuICRtaW47CiAgZWNobyJcbiI7CiAgZWNobyJNQVggPSAiLiAkbWF4OwogIGVjaG8iXG4iOwo/Pg==