Fluoride Dentist
Time limit3sMemory limit1024 MB
Given values a_i, Bjorn (the one with a_i=0) may reinsert himself anywhere; maximize the sum of i*a_i.
- Level
Medium5 of 10
- Topics
- Array, Prefix sum, Greedy, Implementation
- Solved
- No attempts yet
Problem
Björn and other people are standing in line to see the fluoride dentist. Different people find meeting the fluoride dentist scary to different degrees. The people are numbered from to , and person stands in position in the line. Person also has a value , which shows how reluctant the person is to meet the fluoride dentist. Person 's happiness with their position in the line is . Some people may have a negative , which means they actually want to meet the fluoride dentist and are therefore sad about having to wait.
Björn is the only person who is completely indifferent to meeting the fluoride dentist, that is, he is the only person with . He is also very kindhearted, so he decides to leave the line and then re-enter the line at some position so that the total happiness of everyone in the line becomes as large as possible. Write a program that, given the values for all people, computes the maximum sum of happiness in the line when Björn stands in an optimal position.
Input
The first line contains an integer , the number of people in the line. The next line contains integers, where the th integer is . , .
Output
Print one line with a single integer: the maximum total happiness in the line.