SHARE
TWEET

Untitled

a guest Sep 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $arr = array_map('intval', explode(' ', readline()));
  4. $arrDeletedElements = [];
  5. while(true)
  6. {
  7.     if(count($arr) == 0)
  8.     {
  9.         $sum = 0;
  10.         for($i = 0; $i < count($arrDeletedElements); $i++)
  11.         {
  12.             $sum += $arrDeletedElements[$i];
  13.         }
  14.         echo $sum;
  15.         return;
  16.     }
  17.     $index = intval(readline());
  18.     switch ($index)
  19.     {
  20.         case $index >= 0 && $index < count($arr):
  21.             $valueElement = $arr[$index];
  22.             array_splice($arr, $index, 1);
  23.             $arrDeletedElements[] = $valueElement;
  24.             $arr = increaseOrDecrease($arr,$valueElement);
  25.             print_r($arr);//To Check Progress and HELP
  26.             break;
  27.         case $index < 0:
  28.             $valueElement = $arr[0];
  29.             array_splice($arr, 0, 1, $arr[count($arr)-1]);
  30.             $arrDeletedElements[] = $valueElement;
  31.             $arr = increaseOrDecrease($arr,$valueElement);
  32.             print_r($arr);//To Check Progress and HELP
  33.             break;
  34.         case $index > count($arr)-1:
  35.             $valueElement = $arr[count($arr)-1];
  36.             array_splice($arr, count($arr)-1, 1, $arr[0]);
  37.             $arrDeletedElements[] = $valueElement;
  38.             $arr = increaseOrDecrease($arr,$valueElement);
  39.             print_r($arr); //To Check Progress and HELP
  40.             break;
  41.     }
  42. }
  43.  
  44.  
  45.  
  46. function increaseOrDecrease($array,$deletedEle)
  47. {
  48.     for($i = 0; $i < count($array); $i++)
  49.     {
  50.         if($array[$i] <= $deletedEle)
  51.         {
  52.             $array[$i] += $deletedEle;
  53.         }
  54.         else
  55.         {
  56.             $array[$i] -= $deletedEle;
  57.         }
  58.     }
  59.     return $array;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top