链接:https://codeforces.com/contest/1355/problem/D
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
代码:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include<iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
ll n,m,t,k,s,ans;
ll a[200001];
int main()
{
cin>>n>>s;
k=floor(s*1.0/n);
if(k!=1)
{
cout<<"YES"<<endl;
t=s%n;
for(int i=1;i<=t;i++)
{
cout<<k+1<<' ';
}
for(int i=t+1;i<=n;i++)
{
cout<<k<<" ";
}
cout<<endl;
cout<<1<<endl;
}
else
{
cout<<"NO"<<endl;
}
}

本文探讨了在CodeForces平台上的策略性竞赛问题,通过分析特定比赛案例,提出了一种有效的竞赛策略。该策略围绕如何构造数组以赢得游戏,涉及数学计算、逻辑推理和编程实现,展示了算法设计的精妙之处。
409

被折叠的 条评论
为什么被折叠?



