Polish version    English version  
  History of OI -> IV OI 1996/1997 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
IV Olimpiada Informatyczna 1996/1997

Task: LOT
Author: Wojciech Guzicki
Airports

II stage contest  
Source fileLOT.??? (e.g. PAS,C, CPP)
Executable fileLOT.EXE
Input fileLOT.IN
Output fileLOT.OUT

There are n towns with their own airports in the country X. We know the maximal capacities of the airports - the airport in the town Mi can have at most di connections with other towns. The task is to design the net of air connections among the towns in such a way that the town Mi has exactly di connections with other towns. We assume that connections are two-way and that each pair of towns has at most one connection between them.

Task

Write a program that:
  • reads the number of towns n and the numbers di from the text file LOT.IN,
  • designs the net of air connections in such a way that for every i, 1 <= i <= n, the town Mi has exactly di connections with other towns,
  • writes the list of all connections to the file LOT.OUT.
We assume that for the given data a solution exists. If there exists more than one solution the program should find only one.

Input

In the first line of the text file LOT.IN there is written one integer n, 3 <= n <= 500, which is the number of towns.

In the following n lines there are written positive integers di (one integer in each line).

Output

Your program should write all the connections of the created net to the text file LOT.OUT. The description of each connection consists of two positive integers separated by a single space. These integers are the numbers of two connected towns. Each description should be placed in a separate line. The numbers of towns in a line can be written in an arbitrary order. Similarly, the order of connections is not important.

Example

For the file:
6
2
3
2
4
1
2
an example of a correct solution is the file LOT.OUT
5 4
4 2
1 2
2 3
6 3
4 6
4 1





Print friendly version