1. 程式人生 > >codeforces D. Walking Between Houses(思維+貪心)

codeforces D. Walking Between Houses(思維+貪心)

題意:給出n,k,s,初始位置為1,在x座標軸上可到達的最遠位置為n,問恰好走k步能否使得所走距離的和剛好等於s

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 kkmoves.

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

題解:一開始我的想法就是,尋求一個關係式(n-1)*x+(k-x)m  =s 來下手,後來找不到什麼方法,但可以確定是個思維題

分析: 
每次至少移動一個單位的距離,至多移動n-1個單位的距離,所以要想完成上述要求每次決策前後一定要滿足條件: 
k <= s && k*(n-1) >= s

假設當前決策為移動x單位的距離,還有k步可以走,還需要走s距離,所以要滿足下述條件: 
(k-1 <= s-x) && (x <= n-1)

得:max(x) = min( (s - k + 1) , (n-1) ) 
因此我們的決策為:每次移動的大小為 s與k的差值 和 n-1 中的較小值,即每次可以移動的x最大值,使得s和所走距離

儘快的相等。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include <vector>
#include<queue>
#include <stack>
#include <map>
#define maxn 100005
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
LL n,k,s;
struct node
{

};
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k>>s;
    LL t1=0;
    t1=k*(n-1);
    if(s>t1||k>s)
    {
       cout << "NO\n";
    }
    else
    {
       cout << "YES\n";
       LL x,last;
       LL cnt=0;
       last=1;
       while(s>0)
       {
          x=min(s-k+1,n-1);
          if(cnt%2==0)
          {
             cout << last+x << ' ';
             last=last+x;
             cnt++;
          }
          else
          {
             cout << last-x << ' ';
             last=last-x;
             cnt++;
          }
          k--;
          s-=x;
       }
       cout << endl;
       //(n-1)*x+k-x  =s
    }
    return 0;
}