C - Platforms Jumping CodeForces - 1256C(贪心)

There is a river of width nn . The left bank of the river is cell 00 and the right bank is cell n+1n+1 (more formally, the river can be represented as a sequence of n+2n+2 cells numbered from 00 to n+1n+1 ). There are also mm wooden platforms on a river, the ii -th platform has length cici (so the ii -th platform takes cici consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed nn .

You are standing at 00 and want to reach n+1n+1 somehow. If you are standing at the position xx , you can jump to any position in the range [x+1;x+d][x+1;x+d] . However you don't really like the water so you can jump only to such cells that belong to some wooden platform. For example, if d=1d=1 , you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells 00 and n+1n+1 belong to wooden platforms.

You want to know if it is possible to reach n+1n+1 from 00 if you can move any platform to the left or to the right arbitrary number of times (possibly, zero) as long as they do not intersect each other (but two platforms can touch each other). It also means that you cannot change the relative order of platforms.

Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).

For example, if n=7n=7 , m=3m=3 , d=2d=2 and c=[1,2,1]c=[1,2,1] , then one of the ways to reach 88 from 00 is follow:

The first example: n=7n=7 .

Input

The first line of the input contains three integers nn , mm and dd (1≤n,m,d≤1000,m≤n1≤n,m,d≤1000,m≤n ) — the width of the river, the number of platforms and the maximum distance of your jump, correspondingly.

The second line of the input contains mm integers c1,c2,…,cmc1,c2,…,cm (1≤ci≤n,∑i=1mci≤n1≤ci≤n,∑i=1mci≤n ), where cici is the length of the ii -th platform.

Output

If it is impossible to reach n+1n+1 from 00 , print NO in the first line. Otherwise, print YES in the first line and the array aa of length nn in the second line — the sequence of river cells (excluding cell 00 and cell n+1n+1 ).

If the cell ii does not belong to any platform, aiai should be 00 . Otherwise, it should be equal to the index of the platform (11 -indexed, platforms are numbered from 11 to mm in order of input) to which the cell ii belongs.

Note that all aiai equal to 11 should form a contiguous subsegment of the array aa of length c1c1 , all aiai equal to 22 should form a contiguous subsegment of the array aa of length c2c2 , ..., all aiai equal to mm should form a contiguous subsegment of the array aa of length cmcm . The leftmost position of 22 in aa should be greater than the rightmost position of 11 , the leftmost position of 33 in aa should be greater than the rightmost position of 22 , ..., the leftmost position of mm in aa should be greater than the rightmost position of m−1m−1 .

See example outputs for better understanding.

Examples

Input

7 3 2
1 2 1

Output

YES
0 1 0 2 2 0 3 

Input

10 1 11
1

Output

YES
0 0 0 0 0 0 0 0 0 1 

Input

10 1 5
2

Output

YES
0 0 0 0 1 1 0 0 0 0 

Note

Consider the first example: the answer is [0,1,0,2,2,0,3][0,1,0,2,2,0,3] . The sequence of jumps you perform is 0→2→4→5→7→80→2→4→5→7→8 .

Consider the second example: it does not matter how to place the platform because you always can jump from 00 to 1111 .

Consider the third example: the answer is [0,0,0,0,1,1,0,0,0,0][0,0,0,0,1,1,0,0,0,0] . The sequence of jumps you perform is 0→5→6→110→5→6→11 .

题意:

就是给你一个整数n代表这个河流的宽度,m代表你有几个木板子可以使用,d代表你一次能跳的最远距离;

这里主要就是给你的木板子必须使用完。

思路:

贪心。

这里主要是要把题目上面给你的木板子都要用完,但也要尽力的到达对岸,所以首先就是贪心,中间做一下情况判断和处理,具体的话看代码吧。

代码如下:

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,d;
int a[1200],s[1200],b[1200];
int main()
{
    while(~scanf("%d %d %d",&n,&m,&d))
    {
        memset(s,0,sizeof(s));//后缀和
        memset(a,0,sizeof(a));//输入的每个木板的长度
        memset(b,0,sizeof(b));//存储木板摆放位置即最后结果
        for(int i=1; i<=m; i++)
            scanf("%d",&a[i]);
        for(int i=m; i>=1; i--)
            s[i]=s[i+1]+a[i];
        int j=0,k=0,flag=0;//j为第几个木板,k为所能到达的地方,flag用来标记能否达到n+1这个位置
        while(1)
        {
            j++;
            k+=d;
            if(!a[j]&&k<n+1)//如果没有木板并且达不到n+1的位置,直接跳出循环
                break;
            if(k+s[j]>=n+1)//如果达到的位置与后缀和大于等于n+1证明可以到达,赋值之后就跳出循环
            {
                flag=1;//标记可到达
                k=n+1-s[j];//开始从这个坐标给予赋值(赋予的值就是用到的木板是第几个)
                for(int i=j; i<=m; i++)
                {
                    while(a[i]--)
                        b[k++]=i;
                }
                break;
            }
            while(1)//这里就是对于木板放的位置所赋予的值。
            {
                b[k]=j;
                a[j]--;
                if(a[j]==0)
                    break;
                k++;
            }
        }
        if(flag==1)
        {
            printf("YES\n");
            for(int h=1; h<=n; h++)
                printf("%d%c",b[h],h==n?'\n':' ');
        }
        else
            printf("NO\n");
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值