Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $numbers = array_map('intval', explode(' ', readline()));
- $bombNumbers = array_map('intval', explode(' ', readline()));
- for ($i = 0; $i < count($numbers); $i++) {
- if ($numbers[$i] === $bombNumbers[0]) {
- if ($bombNumbers[1] + $i >= count($numbers)) {
- array_splice($numbers, $i, count($numbers) - $i);
- array_splice($numbers, $i - $bombNumbers[1], $bombNumbers[1]);
- break;
- }
- if ($i - $bombNumbers[1] < 0) {
- if ($i === 0) {
- array_splice($numbers, 0, 1 + $bombNumbers[1]);
- $i = -1;
- } else {
- array_splice($numbers, 0, $i);
- array_splice($numbers, $i + 1, $bombNumbers[1] - 1);
- $i -= $bombNumbers[1] + 1;
- }
- } else {
- array_splice($numbers, $i - $bombNumbers[1], ($bombNumbers[1] * 2) + 1);
- $i -= $bombNumbers[1] + 1;
- }
- }
- }
- echo array_sum($numbers);
Add Comment
Please, Sign In to add comment