CF976D.Degree Set

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence of nn positive integers d1,d2,...,dnd_{1},d_{2},...,d_{n} ( d1<d2<...<dnd_{1}<d_{2}<...<d_{n} ). Your task is to construct an undirected graph such that:

  • there are exactly dn+1d_{n}+1 vertices;
  • there are no self-loops;
  • there are no multiple edges;
  • there are no more than 10610^{6} edges;
  • its degree set is equal to dd .

Vertices should be numbered 11 through (dn+1)(d_{n}+1) .

Degree sequence is an array aa with length equal to the number of vertices in a graph such that aia_{i} is the number of vertices adjacent to ii -th vertex.

Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.

It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 10610^{6} edges.

Print the resulting graph.

输入格式

The first line contains one integer nn ( 1<=n<=3001<=n<=300 ) — the size of the degree set.

The second line contains nn integers d1,d2,...,dnd_{1},d_{2},...,d_{n} ( 1<=di<=10001<=d_{i}<=1000 , d1<d2<...<dnd_{1}<d_{2}<...<d_{n} ) — the degree set.

输出格式

In the first line print one integer mm ( 1<=m<=1061<=m<=10^{6} ) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 10610^{6} edges.

Each of the next mm lines should contain two integers viv_{i} and uiu_{i} ( 1<=vi,ui<=dn+11<=v_{i},u_{i}<=d_{n}+1 ) — the description of the ii -th edge.

输入输出样例

  • 输入#1

    3
    2 3 4
    

    输出#1

    8
    3 1
    4 2
    4 5
    2 5
    5 1
    3 2
    2 1
    5 3
    
  • 输入#2

    3
    1 2 3
    

    输出#2

    4
    1 2
    1 3
    1 4
    2 3
    
首页