$LocVal) { foreach($y as $key2=>$val2) { if($LocVal >= ($val2-$r[$key2]) && $LocVal <= ($val2+$r[$key2])) { $cntCloud[$key]++; //if($p[$key] > $max_population) { // $max_population = $p[$key]; // $max_population_key = $key; // $cntCloud[$key]++; //} } else { $resPopul += $p[$key]; //no cloud add to population } } } //} $max_population = -1; //print_r($cntCloud); foreach($cntCloud as $key=>$val) { //find who has one cloud if($val == 1 && $p[$key] > $max_population) $max_population = $p[$key]; } return $max_population + $resPopul; } fscanf($handle, "%i",$n); $p_temp = fgets($handle); $p = explode(" ",$p_temp); $p = array_map('intval', $p); $x_temp = fgets($handle); $x = explode(" ",$x_temp); $x = array_map('intval', $x); fscanf($handle, "%i",$m); $y_temp = fgets($handle); $y = explode(" ",$y_temp); $y = array_map('intval', $y); $r_temp = fgets($handle); $r = explode(" ",$r_temp); $r = array_map('intval', $r); $result = maximumPeople($p, $x, $y, $r); echo $result . "\n"; ?>