#P7403. Friendship Assignment

    ID: 20598 Type: Default 1000ms 256MiB

Friendship Assignment

Friendship Assignment

There are N people, and the ith person wants to have GiG_i friends. Each friendship is mutual. Your task is to assign friendships between these people such that for every person i, the number of friends they have is exactly GiG_i. If such an assignment exists, output the list of friendship pairs; otherwise, output -1.

Note: Each edge (i, j) increases the friend count for both person i and person j, and each pair is counted only once.

inputFormat

The first line contains a single integer NN, the number of people.
The second line contains NN integers G1,G2,,GNG_1, G_2, \ldots, G_N, where GiG_i is the number of friends person i wants.

outputFormat

If a valid friendship assignment exists, first output an integer MM, the number of friendship pairs, followed by MM lines each containing two integers (1-indexed) representing a pair of friends. Otherwise, output -1.

sample

4
1 2 1 0
2

2 1 2 3

</p>