Problems > Prefix Maxima

Prefix Maxima

Difficulty: 900 3500 ms 128 MB

implementation

For every position print the maximum of the first i elements.

Input: the first line has N; the second line has N integers.

Output: N integers: the running maximum at each position.

Constraints:

  • 1 ≤ N ≤ 105
  • -10000 ≤ ai ≤ 10000

Sample Tests

Input 1
4
2 1 5 3
Output 1
2 2 5 5
Input 2
1
-7
Output 2
-7

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.