Shoot for the Win 0/100
Не мога да разбера как да работя пряко с индексите. Може ли малко пояснение?
Условие:
https://judge.softuni.bg/Contests/Practice/Index/2305#1
Write a program that helps you keep track of your shot targets. You will receive a sequence with integers, separated by single space, representing targets and their value. Afterwards, you will be receiving indices until the "End" command is given and you need to print the targets and the count of shot targets.
Every time you receive an index, you need to shoot the target on that index, if it is possiblie.
Everytime you shoot a target, its value becomes -1 and it is considered shot. Along with that you also need to:
- all the other targets, which have greater values than your current target, with its value.
- All the targets, which have less than or equal value to the shot target, you need to increase with its value.
Keep in mind that you can't shoot a target, which is already shot. You also can't increase or reduce a target, which is considered shot.
When you receive the "End" command, print the targets in their current state and the count of shot targets in the following format:
"Shot targets: {count} -> {target1} {target2}… {targetn}"
Input / Constraints
- On the first line of you will receive a sequence of integers, separated by a single space – the targets sequence.
- On the next lines, until the "End"command you be receiving integers each on a single line – the index of the target to be shot.
Output
- The format of the output is described above in the problem description.
Examples
Input |
Output |
Comments |
24 50 36 70 0 4 3 1 End |
Shot targets 3 -> -1 -1 130 -1 |
First we shoot target on index 0. It becomes equal to -1 and we start going through the rest of the targets. Since 50 is more than 24, we reduce it to 26 and 36 to 12 and 70 to 46. The sequence looks like that: -1 26 12 46 The next index is invalid, so we don't do anything. Index 3 is valid and after the operations our sequence should look like that: -1 72 58 -1 Then we take the first index with value 72 and our sequence looks like that: -1 -1 130 -1 Then we print the result after the "End" command. |