#include #include #include #include #include using namespace std; int minc(int n) { int sum=0; int pow2=1; //if(pow2>n)return 0; //return minc(n-pow2,pow2*2); while(pow2<=n) { sum+=n-pow2; n-=pow2; pow2*=2; } return sum; } int maxc(int size){return (size*(size-1)/2);} bool lenareverse(int sorted[],int i,int size,int comparisons) { if(size==0){cout<(size*(size-1)/2)){return false;} comparisons-=size-1; int left=0,right=size-1; //elements remaining int pivot = sorted[i]; //pivot = left while(right>=left) { int lc=0,rc=0; int totalminc= minc(left)+minc(right); int totalmaxc= maxc(left)+maxc(right); if(comparisons>=totalminc&&comparisons<=totalmaxc) { temparray[left]=pivot; int comparisonl=0,comparisonr=comparisons; while(comparisonr>=comparisonl) { if(lenareverse(sorted,left+1,left,comparisonl)&&lenareverse(sorted,left+1,left,comparisonl)){return true;break;} } } } return false; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int q=0; cin>>q; while(q-->0) { int len,c; cin>>len>>c; int n=len; if(c>(n*(n-1)/2)){cout<<"-1";continue;} int a[n]; for(int i=0;i