You have found a treasure map. It leads to n gold mines. Each mine produces gold every day, but the daily haul shrinks by a fixed amount as the days pass. Mine i produces gi on day 1 and loses di per day, so on day k mine i produces max(0, gi−(k−1)×di). A mine never produces a negative amount.
Paths connect the mines, and crossing one path takes a whole number of days. You collect nothing while you travel.
On day 1 you stand at mine 1 and take all of that day's gold from it. You cannot stay at the same mine on two days in a row, so after collecting you have to leave along a path. You may come back to a mine you left earlier, and on the day you come back you take that mine's gold for that day again. You may end the trip at any moment.
Find the largest total amount of gold you can collect.