Score of a Subsequence
InterviewTime limit2sMemory limit512 MB
Find the maximum over all contiguous subarrays of the weighted sum where the k-th element from the subarray start contributes k times its value.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
The score of a sequence is .
A contiguous subsequence is a sequence of its own, so the weights count again from its first term. The score of the contiguous subsequence is .
Write a program that finds the largest score among the contiguous subsequences of . A subsequence of length 0 can be chosen, and its score is 0.
Input
The first line contains ().
The second line contains . ()
Output
Print the largest score among the contiguous subsequences of on the first line.