Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution($A, $B, $M, $X, $Y) {
- // write your code in PHP5.5
- $capacityTempControl = 1;
- $weightTempControl = 0;
- $elevatorMaxWeight = $Y;
- $elevatorCapacity = $X;
- $rideControl = 1;
- $rides = array();
- for ($i = 0; $i <= (count($A)-1); $i++) {
- if($capacityTempControl <= $elevatorCapacity && ($weightTempControl+$A[$i]) <= $elevatorMaxWeight) {
- $rides[$rideControl][] = $B[$i];
- $weightTempControl+=$A[$i];
- $capacityTempControl++;
- } else {
- $rideControl++;
- $rides[$rideControl][] = $B[$i];
- $capacityTempControl = 2;
- $weightTempControl = $A[$i];
- }
- }
- $stopCountVar = 0;
- $lastStopTempCount = -1;
- foreach ($rides as $value) {
- foreach ($value as $finalVal) {
- if($lastStopTempCount != $finalVal) {
- $lastStopTempCount = $finalVal;
- $stopCountVar++;
- }
- }
- $stopCountVar++;
- $lastStopTempCount = -1;
- }
- return($stopCountVar);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement