当前位置:网站首页>D. Game With Array
D. Game With Array
2022-08-10 20:44:00 【秦小咩】
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
做多了思路自然产生
#include<iostream>
#include<cstdio>
#include<cstring>
# include<iomanip>
#include<algorithm>
#define mo 998244353;
using namespace std;
typedef long long int ll;
int main()
{
int n,m;
cin>>n>>m;
if(m>=2*n)
{
cout<<"YES"<<endl;
int up=m/2;
for(int i=1;i<n;i++)
{
cout<<1<<" ";
}
cout<<m-(n-1)<<endl;
cout<<m/2<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}
边栏推荐
- Heme - gold nanoparticles (Heme - AuNP) composite nanometer enzyme | gold nanoparticles nuclear porous hollow carbon nanometer spherical shell (Au @ HCNs) nano enzyme
- Rider调试ASP.NET Core时报thread not gc-safe的解决方法
- 第五届“强网杯”全国网络安全挑战赛(线上赛)
- PostgreSQL — 安装及常用命令
- Pt/CeO2 monatomic nanoparticles enzyme | H - rGO - Pt @ Pd NPs enzyme | carbon nanotube load platinum nanoparticles peptide modified nano enzyme | leukemia antagonism FeOPtPEG composite nano enzyme
- 三子棋的设计和代码
- 日期选择器组件(限制年份 设定仅展示的月份)
- MySQL查询数据库中的表和字段
- 双 TL431 级联振荡器
- 【图像分类】2018-MobileNetV2
猜你喜欢
QSslSocket has not been declared
2020 ICPC Shanghai Site G
每日一R「03」Borrow 语义与引用
(十二)STM32——NVIC中断优先级管理
Ransom Letter Questions and Answers
Pt/CeO2 monatomic nanoparticles enzyme | H - rGO - Pt @ Pd NPs enzyme | carbon nanotube load platinum nanoparticles peptide modified nano enzyme | leukemia antagonism FeOPtPEG composite nano enzyme
The 2021 ICPC Asia Shanghai Regional Programming Contest D、E
npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
【go】依赖注入
Ferritin particle-loaded raltitrexed/pemetrexed/sulfadesoxine/adamantane (scientific research reagent)
随机推荐
Detailed explanation and use of each module of ansible
Transferrin-modified vincristine-tetrandrine liposomes | transferrin-modified co-loaded paclitaxel and genistein liposomes (reagents)
【语义分割】2016-SegNet TPAMI
2021DozerCTF
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
mysql服务器参数设置
npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
双 TL431 级联振荡器
kuberentes Auditing 入门
什么是抽象类?什么时候用?什么是接口?抽象类与接口的区别?
Multifunctional Nanozyme Ag/PANI | Flexible Substrate Nano ZnO Enzyme | Rhodium Sheet Nanozyme | Ag-Rh Alloy Nanoparticle Nanozyme | Iridium Ruthenium Alloy/Iridium Oxide Biomimetic Nanozyme
win7开机有画面进系统黑屏怎么办
设备管理中数据聚类处理
Getting started with kuberentes Auditing
如何提高代码的可读性 学习笔记
QSslSocket has not been declared
用示波器揭示以太网传输机制
Oracle 的开窗函数使用详解(二)
2020 ICPC Shanghai Site G
“蔚来杯“2022牛客暑期多校训练营7 F