Codeforces Round #501 (Div. 3) D(暴力)

D. Walking Between Houses

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

You have to perform kk 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 xx to the house yy, the total distance you walked increases by |x−y||x−y| units of distance, where |a||a| is the absolute value of aa. 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 nn, kk, ss (2≤n≤1092≤n≤109, 1≤k≤2⋅1051≤k≤2⋅105, 1≤s≤10181≤s≤1018) — the number of houses, the number of moves and the total distance you want to walk.

Output

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

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

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

Examples

input

Copy

10 2 15

output

Copy

YES
10 4 

input

Copy

10 9 45

output

Copy

YES
10 1 10 1 2 1 2 1 6 

input

Copy

10 9 81

output

Copy

YES
10 1 10 1 10 1 10 1 10 

input

Copy

10 9 82

output

Copy

NO

 

先考虑在k步下最短路程跟最长路程为多少,如果s不在这个区间内部,说明显然不能满足要求。

我们把s均匀的分成k份,然后直接模拟这个过程即可。

#include<bits/stdc++.h>
#define mp make_pair
#define fir first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int maxn=2e5+10;
const ll mod=1e9+7;
const int maxm=1e6+10;
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const double pi = acos (-1.0);
ll n,k,s;
vector<ll>res,v;
int main(){
    cin>>n>>k>>s;
    ll div=s/((n-1));
    ll remain=s%((n-1));
    ll Max=k*(n-1);
    if (Max<s){
        cout<<"NO"<<endl;
        return 0;
    }
    if (s<k){
        cout<<"NO\n";
        return 0;
    }
    ll temp=s/k;
    remain=s%k;
    for (int i=0;i<remain;i++)
        v.pb(temp+1);
    for (int i=0;i<k-remain;i++)
        v.pb(temp);
    ll beg=1;
    cout<<"YES\n";
    for (int i=0;i<v.size();i++){
        if (beg+v[i]<=n){
            cout<<beg+v[i]<<" ";
            beg=beg+v[i];
        }
        else{
            cout<<beg-v[i]<<" ";
            beg=beg-v[i];
        }
    }
    cout<<endl;
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值