D. Game With Array

Problem - D - Codeforces

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

题意: Petya要创建一个n个数的数组,总和为s,你要给出一个数k,然后Vasya要在这个数组里面挑几个数总和为k或者s-k,如果找不到那就Petya赢打印yes,否则打印no

原本思路就是构造1 1 1 1....s-n+1 那只要给出一个非1 和非s-n+1的数就行,比如s-n,但是要注意

前面的几个1的总和可以等于k,或者s-k,那就要特判一下也就是s-n和s-(s-n)一定大于前面的所有1的总和。这样就找不出来了

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<string.h>
using namespace std;
// ctrl+shift+C 注释
//ctrl+shift+x 取消
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;
const int N=2e5+10;
const ll M=1e18+10;
const int mod=1e9+7;
int a[N],sum[N];
priority_queue<int,vector<int>,greater<int> >pq;
set<int>se;
map<int,int>mp;
queue<int>qu;
vector<int>v;
deque<int>de;
int n,s;
void solve()
{
    cin>>n>>s;
    if(n==1)
    {
        if(s==1)
        {
            NO
            return;
        }
       YES
       cout<<s<<endl;
       cout<<s-1<<endl;
       return;
    }
    if(s==n+1||s<=n*2-1)
    {
        NO
        return;
    }
    YES
    for(int i=1;i<n;i++)
    {
        cout<<1<<" ";
    }
    cout<<s-n+1<<endl;
    cout<<s-n<<endl;
}
signed main()
{
   int t=1;
   //cin>>t;
   while(t--)
   {
       solve();
   }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值