#include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef vector VI; #define REP(i,n) for(int i=0, i##_len=(n); i inline void amin(T &x, const T &y) { if (y inline void amax(T &x, const T &y) { if (x void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } // H(N) := N * (N-1) / 2; // L(N) := 0 if N <= 1 // L((N-1)/2) + L(N- // 1 3 6 10 int N; LL H[100111]; LL L[100111]; bool rec(int *A, int s, int len, LL c) { if (len == 0) return c == 0; if (len == 1) { *A = s; return c == 0; } if (H[len] == c) { REP (i, len) A[i] = s + i; return true; } if (c < L[len] || H[len] < c) return false; if (L[len-1] <= c - (len - 1)) { *A = s; rec(A+1, s+1, len-1, c - (len - 1)); return true; } int k = (len - 1) / 2; while (k >= 0) { int g = len - 1 - k; *A = s + k; LL tmp; tmp = len - 1 + L[k]; if (L[g] <= c - tmp && c - tmp <= H[g]) { if (rec(A + 1, s, k, L[k]) && rec(A + 1 + k, s + k + 1, g, c - tmp)) { return true; } } tmp = len - 1 + H[k]; if (L[g] <= c - tmp && c - tmp <= H[g]) { if (rec(A + 1, s, k, H[k]) && rec(A + 1 + k, s + k + 1, g, c - tmp)) { return true; } } k--; } return false; assert(false); } int A[100111]; int main() { for (int i=2; i<100111; i++) { int k = (i - 1) / 2; L[i] = (i-1) + L[k] + L[i-1-k]; H[i] = (LL)i * (i-1) / 2; } REP (i, 10) eprintf("%lld %lld\n", L[i], H[i]); scanf("%d", &N); REP ($, N) { int len; LL C; scanf("%d%lld", &len, &C); if (L[len] <= C && C <= H[len]) { if (rec(A, 1, len, C)) { rprintf("%d", A, A+len); } else { puts("-1"); } } else { puts("-1"); } } return 0; }