Walking Between Houses(CodeForces - 1015D)

本文探讨了一个模拟行走的问题,从编号1的房子出发,在限定步数内达到指定的总行走距离。通过合理的策略选择,确保能够在规定的步数内完成目标距离的行走。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are nn houses in a row. They are numbered from 1 to n in order from left to right. Initially you are in the house 1.

You have to perform k moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house x to the house y, the total distance you walked increases by |x−y| units of distance, where |a| is the absolute value of a. It is possible to visit the same house multiple times (but you can't visit the same house in sequence).

Your goal is to walk exactly ss units of distance in total.

If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly kk moves.

Input

The first line of the input contains three integers n, k, s (2≤n≤109, 1≤k≤2⋅105, 1≤s≤1018) — the number of houses, the number of moves and the total distance you want to walk.

Output

If you cannot perform k moves with total walking distance equal to s, print "NO".

Otherwise print "YES" on the first line and then print exactly k integers hihi (1≤hi≤n) on the second line, where hi is the house you visit on the i-th move.

For each j from 1 to k−1 the following condition should be satisfied:hj≠hj+1. Also h1≠1 should be satisfied.

Examples

Input

10 2 15

Output

YES
10 4 

Input

10 9 45

Output

YES
10 1 10 1 2 1 2 1 6 

Input

10 9 81

Output

YES
10 1 10 1 10 1 10 1 10 

Input

10 9 82

Output

NO

题解:给了1-n这n个位置,从1开始走,每次必须走到相对于当前位置的另外一个位置,问是否可以用k步走s的距离,每次走的距离为|pos1-pos2|(pos1为原位置,pos2为走到的位置),模拟。

代码如下:

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 32007
#define N 200005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
using namespace std;
typedef long long ll;



int main()
{
    long long n, m, k;
    while(cin>>n>>m>>k)
    {
        if((n-1)*m<k||m>k)
        {
            cout<<"NO"<<endl;
            continue;
        }
        cout<<"YES"<<endl;
        int Now=1;
        k-=m;//保证每个位置上的数都大于1
        while(m--)
        {
            if(k>=n-2)//判断这一步是否能走最大距离
            {
                k-=n-2;
                if(Now==1)
                    Now=n;
                else
                    Now=1;
            }
            else if(k>0)//判断最后一步大小
            {
                if(Now==1)
                    Now=1+1+k;
                else
                    Now=n-(1+k);
                k=0;
            }
            else//不走最大步数的情况
            {
                if(Now==n)
                    Now=n-1;
                else
                    Now++;
            }
            cout<<Now<<' ';
        }
        cout<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值