首页 > 其他 > 详细

D. Game With Array

时间:2020-05-17 12:50:54      阅读:68      评论:0      收藏:0      [点我收藏+]

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 NN positive integers. Sum of all elements in his array should be equal to SS. Then Petya has to select an integer KK such that 0KS0≤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 KK or SKS−K. Otherwise Vasya loses.

You are given integers NN and SS. 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 NN and SS (1NS1061≤N≤S≤106) — 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 NN positive integers with sum equal to SS. In the third line print KK. 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).

地址:http://codeforces.com/contest/1355/problem/D

思路:由于数据过大,且要输出数组,所以无法枚举,通常时令数组的前 n-1个数为一个常数,再由最后一个元素去根据需求调整。此题中数组和K都是自己设定,只要有一种可能PETYA就赢,那么设K=1,数组中的前n-1个元素都设为2,第n个元素为S-(n-1)*2 ,只要第n个元素大于1 ,那么就成立.

int main()
{
    int t = 1;
    while (t--)
    {
        int n, s;
        cin >> n >> s;

        if (s-2*(n-1)<=1) cout << "NO\n";
        else
        {
            cout << "YES\n";
            for (int i = 1; i < n; i++) cout << "2 ";
            cout << s - 2 * (n - 1) <<endl;
            cout << "1" << endl;
        }


    }
    return 0;
}

 

 

 

D. Game With Array

原文:https://www.cnblogs.com/yin101/p/12904716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!