| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12399 | Beautiful Number |
|
| 12427 | AAAAdd |
|
Description
Let’s define an array element arr[i] is beautiful if there’s no element before arr[i] is greater than arr[i].In the other words, if arr[i] is beautiful, then arr[i] < arr[j] is false for all 0 ≤ j < i.
Your task is to find the largest beautiful element.
Hints:The variable used to record largest beautiful element should be initialized small enough
Input
The first line contains an integer N, meaning the size of array. The second line contains N integers, denoting each element in array.
- 1 <= n <= 1000
- 1 <= array elements <= 100000
Output
Print the largest beautiful element.
Remember to print ‘\n’ on the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains nine different numbers, which are 1 to 9 in some random order, for example, 4 1 5 9 8 7 3 6 2. Now, start from the first place, we get the number 4. It indicates that the next number we need to pick is at the 4th place, which is 9. Likewise, we then go the 9th place and get the number 2. We repeat this process until we go to a place that has already been visited. In this example, we will stop at the second place and get the number 1, because we have found a circle. Therefore, along the way we pick four numbers, 4 9 2 1, and the output is the sum of these numbers, which is 16.
Note that we always start from the first place.
Other examples: Consider the input 2 3 4 5 6 7 8 9 1, the output should be 45 since we will visit the numbers one by one and go back to the beginning. Consider the input 1 9 8 7 6 5 4 3 2, the output should be 1 since we stop immediately and cannot go anywhere. Consider the input 9 2 3 4 5 6 7 8 1, the output should be 10.
Input
A random sequence of the nine different numbers of 1 to 9.
Output
The sum of the numbers being visited. Remember to print a '\n' at the end of the sum.