CP.CPP's blog

By CP.CPP, history, 5 years ago, In English
  • An array A of N integers is given [a1, a2 … aN].
  • Step 1: For every A[i] (1 <= i <= N), create an array B of size m which contains integers [b1, b2 … bm] where B[j] < i (for all 1 <= j <= m) and each A[B[j]] >= A[i].
  • Step 2: Increment B[j]th element in A with 1 (i.e. do A[B[j]] = A[B[j]] + 1, where 1 <= j <= m).
  • Step 3: If i < N, do i = i+1 and goto Step 1, otherwise print array A.

Your task is to print the transformed array A.

Input: First line will contain an integer N, where N represents the number of flowers (integers). Next line will contain N space-separated integers H1 H2 ... HN representing heights of flowers in squential order.

Output: Print N space separated integers that represent heights of flowers after all flowers have been watered.

Constrains 1 <= N <= 10^5 1 <= Hi <= 109

  • SAMPLE INPUT 5 7 5 2 1 8
  • SAMPLE OUTPUT 11 7 3 1 8
  • Explanation 7 5 2 1 8 (begin) -> 8 5 2 1 8 (A[1] >= A[2]) -> 9 6 2 1 8 (A[1], A[2] >= A[3]) -> 10 7 3 1 8 (A[1], A[2], A[3] >= — A[4]) -> 11 7 3 1 8 (A[1] >= A[5])

Full text and comments »

  • Vote: I like it
  • -7
  • Vote: I do not like it