Codeforces Round #643 (Div. 2) D.Game With Array

Codeforces Round #643 (Div. 2) D.Game With Array

题目链接
Petya and Vasya are competing with each other in a new interesting game as they always do.

At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0≤K≤S.

In order to win, Vasya has to find a non-empty subarray in Petya’s array such that the sum of all selected elements equals to either K or S−K. Otherwise Vasya loses.

You are given integers N and S. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

Input

The first line contains two integers N and S (1≤N≤S≤1e6) — the required length of the array and the required sum of its elements.

Output

If Petya can win, print “YES” (without quotes) in the first line. Then print Petya’s array in the second line. The array should contain N positive integers with sum equal to S. In the third line print K. If there are many correct answers, you can print any of them.

If Petya can’t win, print “NO” (without quotes).

You can print each letter in any register (lowercase or uppercase).

Examples

input

1 4

output

YES
4
2

input

3 4

output

NO

input

3 8

output

YES
2 1 5
4

典型的构造题~
我们先考虑输的情况,即 s < 2 ∗ n s<2*n s<2n,为什么?
可以看一下我的思维证明,首先,此时构造的数组必然有 1 1 1,这点很好想,那么 k = 1   o r   k = s − 1 k=1\ or\ k=s-1 k=1 or k=s1就排除了
下面考虑再选一个数 i i i,则可构成 s = i + 1 s=i+1 s=i+1
下面考虑再选一个数 j j j,则可构成 s = i + j + 1 s=i+j+1 s=i+j+1
⋯ \cdots
不难发现每多选一个数,就能多一种选的组合而 n n n 个数恰好 n n n 种组合,即 1 − s 1-s 1s 的所有取值都可取到,所以此时一定会输
s > 2 ∗ n s>2*n s>2n 时, s > 2 ∗ ( n − 1 ) + 2 s>2*(n-1)+2 s>2(n1)+2 s − 2 ∗ ( n − 1 ) > 2 s-2*(n-1)>2 s2(n1)>2,所以我们可以选 k = 1 k=1 k=1,构造数组: 2 , 2 , ⋯   , s − 2 ∗ ( n − 1 ) 2,2,\cdots,s-2*(n-1) 2,2,,s2(n1)
AC代码如下:

#include
using namespace std;
typedef long long ll;

main(){
    int n,s;
    cin>>n>>s;
    if(s>=2*n){
        puts("YES");
        for(int i=0;i<n-1;i++) cout<<2<<" ";
        cout<<s-2*(n-1)<<endl<<1;
    }
    else puts("NO");
}

你可能感兴趣的:(思维,构造,Codeforces)