According to me , this is the logic for above program :-
First we are finding the basic case in which we have just added the number with its index and obtained the array, this will be the scenario in round1.
Now iterating through the array we have found the greatest sum upto the index j, notice he has done it two times , one forward iteration and one backward iteration
Now at any particular index j, we have got the maximum value upto j by forward iteration and maximum value at j by backward iteration, and these two are the only values that we have to focus on as all the sums will be incremented and decremented by the same amount at any round if we can notice the change in the jth index value it will be the maximum
Now we start from the last index i.e. N and we have very smartly used N-A as this will be the number added to the given index at a round 1, notice that all the values at index less than A will also be incremented by the same amount and we know that upto Ath index we have the maximum value already stored so we just have to focus on Ath index.
The other value that can change is the number just next to the Ath index as new value will be put below the upper value thus decrementing its value (as the number placed is 1), so if we can find the max of both the changed value , then that will be the answer for that round
Hope that helps :-)