#P16026. [CSPro 23] 数组推导

[CSPro 23] 数组推导

Background

Luogu’s testdata are for informal communication only and are not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

A1,A2,⋯ ,AnA_1, A_2, \cdots , A_n is an array consisting of nn natural numbers (i.e., non-negative integers). Based on this, we use the array B1⋯BnB_1 \cdots B_n to represent the prefix maximums of AA.

Bi=max⁡A1,A2,⋯ ,AiB_i = \max {A_1, A_2, \cdots , A_i}

As shown above, BiB_i is defined as the maximum value among the first ii numbers in array AA. From this definition, it is easy to know that A1=B1A_1 = B_1, and as ii increases, BiB_i is monotonically non-decreasing. In addition, we use sum=A1+A2+⋯+An\mathrm{sum} = A_1 + A_2 + \cdots + A_n to denote the total sum of the nn numbers in array AA.

Now the array BB is given. We want to reconstruct array AA from the values of BB. Obviously, for a given BB, the values of AA may not be unique. Please compute, among all possible arrays AA, what are the maximum and minimum possible values of sum\mathrm{sum}?

Input Format

Read from standard input.

The first line contains a positive integer nn.

The second line contains nn natural numbers B1,B2,⋯ ,BnB_1, B_2, \cdots , B_n, separated by spaces.

Output Format

Write to standard output.

Output consists of two lines.

The first line outputs an integer, representing the maximum value of sum\mathrm{sum}.

The second line outputs an integer, representing the minimum value of sum\mathrm{sum}.

6
0 0 5 5 10 10
30
15
7
10 20 30 40 50 60 75
285
285

Hint

Sample 1 Explanation

Possible values of array AA include, but are not limited to, the following three cases.

Case 1: A=[0,0,5,5,10,10]A = [0, 0, 5, 5, 10, 10]

Case 2: A=[0,0,5,3,10,4]A = [0, 0, 5, 3, 10, 4]

Case 3: A=[0,0,5,0,10,0]A = [0, 0, 5, 0, 10, 0]

Among them, in the first case sum=30\mathrm{sum} = 30 is the maximum value, and in the third case sum=15\mathrm{sum} = 15 is the minimum value.

Sample 2 Explanation

A=[10,20,30,40,50,60,75]A = [10, 20, 30, 40, 50, 60, 75] is the only possible value, so both the maximum and minimum values of sum\mathrm{sum} are 285285.

Subtasks

50%50\% of the testdata satisfy that array BB is strictly increasing, i.e., 0<B1<B2<⋯<Bn<1050 < B_1 < B_2 < \cdots < B_n < 10^5.

All testdata satisfy n≤100n \leq 100 and array BB is monotonically non-decreasing, i.e., 0≤B1≤B2≤⋯≤Bn≤1050 \leq B_1 \leq B_2 \leq \cdots \leq B_n \leq 10^5.

Translated by ChatGPT 5