A Math Contest P3 - LIS Reconstruction

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Consider a permutation of the first N positive integers, p1,p2,,pN. Define ai as the length of the longest increasing subsequence of p1,p2,,pi.

Given a1,a2,,an, find the lexicographically minimal possible permutation p1,p2,,pN, or determine that no such permutation exists.

Constraints

1N2×105

1aiN

Input Specification

The first line contains an integer, N.

The second line contains N space-separated integers, a1,a2,,aN.

Output Specification

If there is no sequence p that can produce sequence a, output 1; otherwise, output one line containing N positive integers, representing the lexicographically minimal permutation p1,p2,,pN.

Sample Input 1

Copy
3
1 2 2

Sample Output 1

Copy
1 3 2

Explanation for Sample Output 1

Note that

  • The longest increasing subsequence of p1 is 1.
  • The longest increasing subsequence of p1,p2 is 1,3.
  • One of the longest increasing subsequences of p1,p2,p3 is 1,2.

Sample Input 2

Copy
3
1 2 1

Sample Output 2

Copy
-1

Explanation for Sample Output 2

No possible permutation p exists.


Comments

There are no comments at the moment.