思路解析:
可以分为三类情况分开讨论
1、当2*k+1>n时,很显然无法构造
2、当2*k+1==n时,这种情况注意一下细节,注意一下y的取值可能各不相同,另外提供两种测试案例供大家测试:11 32 5 和 11 33 5
3、当2*k+1<n时,在三元组(2,1,2)的基础上构造即可,注意5 8 1 需要输出2 1 2 2 1(保证三元组恰好为一个)。
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define int long long
using T = pair<int, int>;
//set<int>S;
//unordered_map<int, int>mp;
const int N = 2e5 + 10;
int a[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
int n, S, k; cin >> n >> S >> k;
int i;
if (2 * k + 1 > n) {
cout << -1 << endl;
}
else if (2 * k + 1 == n) {
if (k == 0) {
cout << S << endl;
}
else {
int x, flag = 0;
int y;
for (x = 2; x <= S; ++x) {
y = S - (k + 1) * x;
if (y <= 0)break;
if (y >= k && y <= (x - 1) * k) {
flag = 1;
break;
}
}
if (flag == 0)cout << -1 << endl;
else {
int y1 = y / k;
int y2 = S - (k + 1) * x - y1 * (k - 1);
for (i = 1; i <= n; ++i) {
if (i & 1)cout << x << " ";
else {
if (y2 >= x) {
if (i == n - 1)cout << y2 - 2 << " ";
else if (i == n - 3)cout << y1 + 1<<" ";
else if(i==n-5)cout << y1 + 1 << " ";
else cout << y1 << " ";
}
else {
if (i != n - 1)cout << y1 << " ";
else cout << y2 << ' ';
}
}
}cout << endl;
}
}
}
else {
if (k == 0) {
if (S < n)cout << -1 << endl;
else
for (i = 1; i <= n; ++i) {
if (i != n) {
cout << 1 << " ";
}
else {
cout << S - (n - 1) << endl;
}
}
}
else {
if (S - (3 * k + 2) < n - (2 * k + 1))cout << -1 << endl;
else {
for (i = 1; i <= 2 * k + 1; ++i) {
if (i & 1)cout << 2 << " ";
else cout << 1 << " ";
}
if (S == 3 * (k + 1) + 2 && 2 * k + 3 == n) {
cout << 2 << " " << 1 << endl;
}
else {
for (; i <= n; ++i) {
if (i != n)cout << 1 << " ";
else cout << S - k - n << endl;
}
}
}
}
}
}
return 0;
}