#K40792. Maximum Trendiness Sum
Maximum Trendiness Sum
Maximum Trendiness Sum
You are given a sequence of n chapters, each with an associated trendiness score. Your task is to choose a subset of these chapters, respecting the original order, in order to maximize the sum of trendiness scores. Note that adding a chapter with a negative score can reduce the overall sum, so it is better to skip such chapters.
Mathematically, if the chapters' scores are given by \(a_1, a_2, \dots, a_n\), then the maximum trendiness sum is given by:
[ \text{answer} = \sum_{i=1}^{n} \max(a_i,0), ]
However, you must consider the chapters in order (i.e., you cannot rearrange them) and the decision to include a chapter should be based on whether it improves the overall sum.
If all chapters have negative scores, the answer is 0
.
inputFormat
The input is given in two lines:
- The first line contains a single integer
n
— the number of chapters. - The second line contains
n
space-separated integers, representing the trendiness scores of each chapter.
outputFormat
Output a single integer — the maximum sum of trendiness scores achievable by selecting a subset of chapters in order.
## sample4
1 2 3 4
10
</p>