Advertisement
emotrend

Pokemon don't go

Jun 27th, 2019
377
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $sequence = array_map("intval", explode(" ", readline()));
  4. $index = readline();
  5. $sum = 0;
  6.  
  7. while (count($sequence)) {
  8. $index = intval($index);
  9. $removed = null;
  10.  
  11. if ($index < 0) {
  12. $lastEl = $sequence[0];
  13. $sequence[0] = $sequence[count($sequence) - 1];
  14. } else if ($index >= count($sequence)) {
  15. $lastEl = $sequence[count($sequence) - 1];
  16. $sequence[count($sequence) - 1] = $sequence[0];
  17. } else {
  18. $lastEl = array_splice($sequence, $index, 1)[0];
  19. }
  20. $sum += $lastEl;
  21. for ($i = 0; $i < count($sequence);$i++){
  22. if ($sequence[$i] <= $lastEl) {
  23. $sequence[$i] += $lastEl;
  24. } else {
  25. $sequence[$i] -= $lastEl;
  26. }
  27. }
  28. $index = readline();
  29. }
  30. echo $sum;
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement