• D. Game With Array


    D. Game With Array

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    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 0≤K≤S0≤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 S−KS−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 (1≤N≤S≤1061≤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).

    Examples

    input

    Copy

    1 4
    

    output

    Copy

    YES
    4
    2

    input

    Copy

    3 4
    

    output

    Copy

    NO

    input

    Copy

    3 8
    

    output

    Copy

    YES
    2 1 5
    4

    样例可不是白给的,从看样例到解决问题只需五分钟

    根据两个YES和一个NO猜测是m与n是大于二倍关系才能完成表示,并通过手写几个小样例发现确实是这样,而且2倍的时候也能表示

    再考虑通解,抓住大于2倍的特点,我们前n-1个全部填上1,剩下全部填上m-(n-1)

    再把k选成m/2这样的话,无论怎么表示,要么小于m/2,要么大于m/2

    做多了思路自然产生

    1. #include
    2. #include
    3. #include
    4. # include
    5. #include
    6. #define mo 998244353;
    7. using namespace std;
    8. typedef long long int ll;
    9. int main()
    10. {
    11. int n,m;
    12. cin>>n>>m;
    13. if(m>=2*n)
    14. {
    15. cout<<"YES"<
    16. int up=m/2;
    17. for(int i=1;i
    18. {
    19. cout<<1<<" ";
    20. }
    21. cout<-1)<
    22. cout<2<
    23. }
    24. else
    25. {
    26. cout<<"NO"<
    27. }
    28. return 0;
    29. }

  • 相关阅读:
    算法打卡day31|贪心算法篇05|Leetcode 435. 无重叠区间、763.划分字母区间、56. 合并区间
    RedisTemplate操作Redis
    【USB电压电流表】基于STM32F103C8T6 for Arduino
    特征工程/数据预处理超全面总结(持续更新ing...)
    linux之scp命令文件传输
    数巅科技联合长江计算打造AskBot企业智能问答一体机
    STM32 与 ARM 的联系
    深度学习 神经网络(4)线性回归-Pytorch实现房价预测
    GPS卫星位置解算原理与程序设计(C语言)
    学习编程的目的
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126269035