#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
is an array consisting of natural numbers (i.e., non-negative integers). Based on this, we use the array to represent the prefix maximums of .
As shown above, is defined as the maximum value among the first numbers in array . From this definition, it is easy to know that , and as increases, is monotonically non-decreasing. In addition, we use to denote the total sum of the numbers in array .
Now the array is given. We want to reconstruct array from the values of . Obviously, for a given , the values of may not be unique. Please compute, among all possible arrays , what are the maximum and minimum possible values of ?
Input Format
Read from standard input.
The first line contains a positive integer .
The second line contains natural numbers , 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 .
The second line outputs an integer, representing the minimum value of .
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 include, but are not limited to, the following three cases.
Case 1:
Case 2:
Case 3:
Among them, in the first case is the maximum value, and in the third case is the minimum value.
Sample 2 Explanation
is the only possible value, so both the maximum and minimum values of are .
Subtasks
of the testdata satisfy that array is strictly increasing, i.e., .
All testdata satisfy and array is monotonically non-decreasing, i.e., .
Translated by ChatGPT 5