1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <cctype> using namespace std; bool vis[505]; int main() { int n, l, r, s, _, i, sum, fr; scanf("%d", &_); while (_--) { scanf("%d%d%d%d", &n, &l, &r, &s); sum = 0; for (i = 1; i <= n; i++) vis[i] = 0; stack<int> res; for (i = n; res.empty() || res.size() < r - l + 1; i--) { sum += i; res.push(i); vis[i] = 1; } fr = 1; queue<int> ans; while (sum > s) { if (res.empty()) break; int t = res.top(); res.pop(); vis[t] = 0; if (t <= fr) break; if (sum - t + fr <= s) { ans.push(s - sum + t); vis[s - sum + t] = 1; sum = s; break; } sum = sum - t + fr; vis[fr] = 1; ans.push(fr++); } if (sum != s) { printf("-1\n"); continue; } while (!res.empty()) { ans.push(res.top()); res.pop(); } bool flag = 0; sum = 1; if (l > 1) { for (i = 1; i <= n; i++) { if (!vis[i]) { vis[i] = 1; if (flag) printf(" %d", i); else { flag = 1; printf("%d", i); } sum++; if (sum == l) break; } } } while (!ans.empty()) { if (flag) printf(" %d", ans.front()); else { flag = 1; printf("%d", ans.front()); } ans.pop(); } for (i = 1; i <= n; i++) { if (!vis[i]) { if (flag) printf(" %d", i); else { flag = 1; printf("%d", i); } } } printf("\n"); } return 0; }
|