2018 Petrozavodsk Winter Camp, Yandex Cup CFGym 102155H Sketch

11 篇文章 0 订阅

Description

Given a sequence a consisting of integers a1, ..., an, consider all its non-decreasing subsequences of length k. Among all of these take the one with smallest last element. We denote the value of this element with sk.

The sequence s(a) = s1, ..., sl is a sketch for sequence a, where l is the length of the longest non-decreasing subsequence of a.

Building a sketch of the sequence is a standard task while finding the length of the longest non-decreasing subsequence. Here we consider an opposite problem: given a sketch with some missing entries, find any sequence producing this sketch.

Formally, you are given a sequence t1, ..., tk where each element is either a positive integer or  - 1. You have to find a sequence a1, ..., an with each element being an integer between 1 and m, inclusive, satisfying the following properties: length of the sketch of a should be equal to k, and for each index i between 1 and k, if ti ≠  - 1, then si = ti should hold.

Input

First line contains three integers k, n, m (1 ≤ k ≤ 300 000, 1 ≤ n ≤ 300 000, 1 ≤ m ≤ 109), the length of the sketch, the length of the desired sequence and the upper bound on element values respectively.

Next line contains k numbers t1, ..., tk (1 ≤ ti ≤ m or ti =  - 1), the sketch itself.

Output

If a sequence with such sketch exists, output the elements of a desired sequence. In case of multiple answers you may output any of them.

If no valid sequence exists, output a single integer  - 1.

Sample Input

Input

3 4 10
3 7 7

Output

3 7 8 7

Input

3 5 10
3 -1 7

Output

3 6 5 4 7

Input

4 2 10
1 2 3 4

Output

-1

Hint

Sketch of the answer sequence in example 2: 3 4 7.

思路:往a[i]前面插m到(m-a[i]+1),a[i]如果等于-1,那么它的值就取和前一个相同就可以

#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
#define maxn 500050
int a[maxn];
int ans[maxn];
int main()
{
    int k,n,m;
    scanf("%d %d %d",&k,&n,&m);

    a[0]=1;
    for(int i=1; i<=k; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==-1)
        {
            a[i]=a[i-1];
        }
        if(a[i]>m||(a[i]<a[i-1]))
        {
            printf("-1\n");
            return 0;
        }
    }
    if(k>n)
    {
        printf("-1\n");
        return 0;
    }
    int cnt=0;
    for(int i=1; i<=k; i++)
    {
        for(int j=1; j<=m-a[i]; j++)
        {
            if(cnt==n-k)
            {
                break;
            }
            ans[i+cnt]=m-j+1;
            cnt++;
        }
        ans[i+cnt]=a[i];
    }
    if(cnt!=n-k)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d",ans[1]);
    for(int i=2; i<=n; i++)
    {
        printf(" %d",ans[i]);
    }
    printf("\n");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值