https://codeforces.com/problemset/problem/1355/D
We have a constructive problem where we need to construce an array with a required sum value using n elements.
Our task is to determine if there exists a value k and s - k that cannot be the sum of any subsequence from the array.
If n * 2 > s, there is no solution.
However, if n * 2 <= s, we can populate the array with (n - 1) '1' and assign (s - (n - 1)) to the last position of the array.
void solve(){
int n, s;
cin >> n >> s;
if (n * 2 > s){
cout << "No\n";
}
else{
cout << "YES\n";
for (int i = 0; i < n; ++i){
cout << (i < n - 1 ? 1 : (s - n + 1)) << " \n"[i == n - 1];
}
cout << n << '\n';
}
}
标签:sum,there,value,Array,Game,problem,array
From: https://www.cnblogs.com/yxcblogs/p/18071596