定义一个符号
现在有一个由
现在给你所有的
我们考虑贪心构造,每次优先将当前
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int N;
int a[1010]={0};
int hash[1010]={0};
int ans[2020]={0};
int dui[1010]={0};
int st=1,en=0;
int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",&a[i]);
    a[0]=2e9;
    for(int p=1;p<=N*2;p++)
    {
        int i;
        for(i=1;i<=N;i++)
            if(a[i]==0 && hash[i]==0)
                break;
        if(i<=N)
        {
            ans[p]=i;
            for(int j=1;j<i;j++)
                if(a[j]>0)
                    a[j]--;
            dui[++en]=i;
            hash[i]=1;
        }
        else
        {
            if(st>en)
            {
                puts("NO");
                return 0;
            }
            ans[p]=-dui[st];
            for(int j=dui[st]+1;j<=N;j++)
                if(a[j]>0)
                    a[j]--;
            st++;
        }
    }
    puts("YES");
    for(int i=N*2;i>=1;i--)
        printf("%d ",ans[i]);
    return 0;
}原文:http://blog.csdn.net/qq_21995319/article/details/46627653