• 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 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).

    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
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const int mod = 998244353;
    const int N = 2e5 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m%n);
    }
    ll lcm(ll m, ll n)
    {
        return m*n / gcd(m, n);
    }
    
    int main()
    {
        int s, n;
        cin >> n >> s;
        int x;
        n--;
        x = s - n;
        if (x-n<2)
            cout << "NO" << endl;
        else
        {
            cout << "YES" << endl;
            rep(i, 1, n)
                cout << 1<<" ";
            cout << x << endl;
            cout << x - 1 << endl;
        }
        return 0;
    }
  • 相关阅读:
    bzoj1036 [ZJOI2008]树的统计Count(树链剖分)
    poj2348 Euclid's Game
    bzoj3575 [Hnoi2014]道路堵塞
    poj2484 A Funny Game
    bzoj2286 [Sdoi2011]消耗战
    虚树学习笔记
    bzoj4518 [Sdoi2016]征途
    node.js开发环境配置
    js中阻止事件冒泡和浏览器默认行为
    css3 background-clip和background-origin 区别
  • 原文地址:https://www.cnblogs.com/dealer/p/12954954.html
Copyright © 2020-2023  润新知