Video Game

Shefin is playing a game. In this game there are N buildings numbered from 1 to N. Each building has a height of hi. On the top of every building there are some gold coins. The amount of gold coins on the top of the ith building is ai. At the start of a round Shefin will be on the top of the Xth building. He can go to the (X+1)th building from the Xth building, if X < N and the height of the (X + 1)th building is not more than the height of the Xth building. He can also go to the (X - 1)th building if X > 1 and the (X - 1)th building is not taller than the Xth building. Following these rules Shefin will travel through the buildings and collect the gold coins from the top of the buildings. Shefin will play this game for total Q rounds. You will have to tell the maximum amount of gold coin Shefin can collect in each round.

This is a companion discussion topic for the original entry at