DISTK - Editorial

bro use long long for k :neutral_face:

Your solution is great! Motivates me to try finding patterns in such problems which I lazily didn’t.

1 Like

Good explanation

1 Like

my code is failing only for first testcase
I have pasted by code here ,could someone tell me where it fails

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long int n,x,k,count,k1,k2=n;
cin>>n>>x;
bool flag=false;
long int a[n];
for(int i=0;i<n;i++)
{
a[i]=1;
}
k1=2,count=n;
for(int i=1;i<n;i++)
{
if((k1*(k1+1))/2+(n-i-1)<=x)
{
a[i]=a[i-1]+1;
k1++;
}
else
{
int k3=(k1*(k1-1))/2+(n-i);
a[i]=a[i-1]-(x-k3);
k2=i;
break;
}
}
for(int i=k2+1;i<n;i++)
{
a[i]=a[i-1];
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
}

Consider the input

1
6 21

yeah thx,i got the error i had initialized k2 as n before assigning k some value ,so it was taking garbage for this tc

Thanks a lot, feeling dumb now as due to that small error was not able to submit it within time :cry: