#P7403. Friendship Assignment
Friendship Assignment
Friendship Assignment
There are N people, and the ith person wants to have 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 . 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 , the number of people.
The second line contains integers , where is the number of friends person i wants.
outputFormat
If a valid friendship assignment exists, first output an integer , the number of friendship pairs, followed by 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>