C. Platforms Jumping(Codeforces Round #598 (Div. 3))(模拟)

C. Platforms Jumping(Codeforces Round #598 (Div. 3))(模拟)

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Description

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

You are standing at 0 0 0 and want to reach n + 1 n+1 n+1 somehow. If you are standing at the position x x x, you can jump to any position in the range [ x + 1 ; x + d ] [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 = 1 d=1 d=1, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells 0 0 0 and n + 1 n+1 n+1 belong to wooden platforms.

You want to know if it is possible to reach n + 1 n+1 n+1 from 0 0 0 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 = 7 , m = 3 , d = 2 n=7, m=3, d=2 n=7,m=3,d=2 and c = [ 1 , 2 , 1 ] c=[1,2,1] c=[1,2,1], then one of the ways to reach 8 8 8 from 0 0 0 is follow:
The first example: .

Input

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

The second line of the input contains m m m integers c 1 , c 2 , … , c m ( 1 ≤ c i ≤ n , ∑ i = 1 m c i ≤ n ) c_1,c_2,…,c_m (1≤c_i≤n,∑_{i=1}^{m}c_i≤n) c1,c2,,cm(1cin,i=1mcin), where c i c_i ci is the length of the i i i-th platform.

Output

If it is impossible to reach n + 1 n+1 n+1 from 0 0 0, print NOin the first line. Otherwise, print YESin the first line and the array a of length n n n in the second line — the sequence of river cells (excluding cell 0 0 0 and cell n + 1 n+1 n+1).

If the cell i i i does not belong to any platform, a i a_i ai should be 0 0 0. Otherwise, it should be equal to the index of the platform ( 1 1 1-indexed, platforms are numbered from 1 1 1 to m m m in order of input) to which the cell i i i belongs.

Note that all a i a_i ai equal to 1 1 1 should form a contiguous subsegment of the array a a a of length c 1 c_1 c1, all a i a_i ai equal to 2 2 2 should form a contiguous subsegment of the array a a a of length c 2 c_2 c2, …, all a i a_i ai equal to m m m should form a contiguous subsegment of the array a a a of length c m c_m cm. The leftmost position of 2 2 2 in a a a should be greater than the rightmost position of 1 1 1, the leftmost position of 3 3 3 in a a a should be greater than the rightmost position of 2 2 2, …, the leftmost position of m m m in a a a should be greater than the rightmost position of m − 1 m−1 m1.

See example outputs for better understanding.

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] [0,1,0,2,2,0,3]. The sequence of jumps you perform is 0 → 2 → 4 → 5 → 7 → 8 0→2→4→5→7→8 024578.

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

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] [0,0,0,0,1,1,0,0,0,0]. The sequence of jumps you perform is 0 → 5 → 6 → 11 0→5→6→11 05611.

题解

大模拟

如果模板稀缺的话就贪心地把模板往后放;若木板不稀缺,就考虑保证所有木板都有空间放的情况下尽量往后放;若木板数量和剩余的空间数一样的话就直接挨着铺。

代码

#include <iostream>
#include <algorithm>
#include <vector>
#define _for(i, a) for(int i = 0; i < (a); i++)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const LL MAXN = 110;
const LL inf = 0x3f3f3f3f;

LL n, m, d;
LL sum = 0;	//木板长度总数
LL b[1005];
vector<LL> c;

void init() {
	mem(b, 0);
	c.clear();
}

void sol() {
	LL _sum = n;	//剩余的空间
	LL pos = -1;
	LL t = 0;	//木板序号
	while (_sum && t < m) {
		LL tem = min(_sum - sum + 1, d);	//本回合能移动的最大距离
		pos += tem;	//移动人物的位置到木板最左边
		_for(i, c[t]) b[pos + i] = t + 1;	//记录木板序号
		_sum = _sum - tem - c[t] + 1;	//改变剩余的空间数量
		sum -= c[t];	//改变剩余的木板长度
		pos += c[t] - 1;	//再改变任务的位置到木板最右边
		t++;
	}
	if (pos + d < n) {
		cout << "NO\n";
		return;
	}
	cout << "YES\n";
	_for(i, n) {
		cout << b[i] << (i == n - 1 ? "\n" : " ");
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);

	while (cin >> n >> m >> d) {
		init();
		_for(i, m) {
			LL x;
			cin >> x;
			sum += x;
			c.push_back(x);
		}
		sol();
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值