HEALTHY MOMOS SOLUTION
“Chef’s-Momos”, an Indian restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nitin entered Chef’s-Momos, and he was guided to the counter. Now, there are N pieces of momos (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nitin is standing to the point where the i-th momo is placed, is xi meters. Also, the i-th momo has a nutritive value of vi kilocalories.
Nitin can freely walk around the circumference of the counter. When he reach a point where a momo is placed, he can eat that momo and take in its nutrition (naturally, the momo disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new momo will be added to the counter. Also, since Nitin has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
1≤x1< x2 < … < xN < C
All values in input are integers.
Input is given from Standard Input in the following format:
If Nitin can take in at most c kilocalories on balance before he leaves the restaurant, print c.
Example Text Case
NOTE: There are three momos on the counter with a circumference of 20 meters. If he
walks two meters clockwise from the initial place, he can eat a momo of 80 kilocalories.
If he walks seven more meters clockwise, he can eat a momo of 120kilocalories.
If he leaves now, the total nutrition taken in is 200 kilocalories,
and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on
balance, which is the largest possible value.
SOLUTION AFTER CONTEST(POLICY ISSUE)