#P2008. 大朋友的数字

大朋友的数字

Description

There is a group of “big friends” (age 1515 or above). Each of them holds a number, which has exactly 11 digit, i.e., it is between 00 and 99. The score of each big friend is defined as the sum of all numbers in the longest non-decreasing subsequence that appears before them and ends at them. (This sequence must end at that person!) If there are multiple longest non-decreasing subsequences, choose the one whose sequence of indices is lexicographically smallest. Now you are given nn big friends and their numbers. Please compute the score of each person.

Input Format

The first line contains 11 number nn.

The second line contains nn numbers, representing each person’s number.

Output Format

Output nn numbers in one line, representing each person’s score.

5
1 2 5 3 4

1 3 8 6 10

5
1 7 5 9 6

1 8 6 17 12

Hint

[Sample Explanation 11]

The five scores are (1)(1), (1+2)(1+2), (1+2+5)(1+2+5), (1+2+3)(1+2+3), (1+2+3+4)(1+2+3+4).

[Sample Explanation 22]

The five scores are (1)(1), (1+7)(1+7), (1+5)(1+5), (1+7+9)(1+7+9) (there is also (1,5,9)(1,5,9)), (1+5+6)(1+5+6).

Constraints

For 50%50\% of the testdata, 1n5001 \le n \le 500.

For 80%80\% of the testdata, 1n1031 \le n \le 10^3.

For 100%100\% of the testdata, 1n1041 \le n \le 10^4.

Translated by ChatGPT 5