DISCLAIMER: This problem statement contains NO spoilers to the film Avengers: Endgame and is in no way, shape, or form affiliated to Marvel Entertainment. Uses of characters, settings, and scenes are parodical only.
Thanos wants to balance the universe, but the pesky Avengers keep getting in his way. He's hired you, a computer scientist, to help him obtain the infinity stones. Help him find them, and it will put a smile on his face.
The planets in Thanos' path can be represented with an
Since many other people have been collecting these stones, many of the stones are near each other. Thanos can use his minions to collect multiple adjacent stones (stones that are next to each other in an array) in one trip.
Calculate the minimum amount of time, in minutes, for Thanos to collect all
Input Specification
The first line of input will contain two space-separated integers:
The next
Constraints
Output Specification
A single integer: the minimum amount of time that Thanos and his minions need to collect all the infinity stones.
Sample Input
10 6
0
1
1
0
1
0
0
1
1
1
Sample Output
3
Explanation
The stones at index 1 and 2 are adjacent, which increments the time by 1. The stone at index 4 is on its own, so Thanos must collect it by itself, incrementing the time by 1 again. The stones at indices 7, 8 and 9 are all adjacent to one another, and so the time increments by only 1. The final total time is 3.
Comments
I was struggling with this problem for a while because by adjacent they mean any amount of adjacent stones in a row, not just adjacent by one planet. 111111 would still count as one minute because all of the stones are considered adjacent.