Let $k$ be a positive integer. Consider a finite sequence $L_k(n)$ given by
$$\underbrace{1,1,1,1,\ldots, 1}_{k\text{ terms}}, \underbrace{2,2,2,2,\ldots, 2}_{k-1\text{ terms}},\ldots, \underbrace{k-1, k-1}_{2\text{ terms only}}, k.$$
Allegedly, there is a closed-form formula for $L_k(n)$:
$$L_k(n) = k+1 - \left\lfloor \tfrac{1}{2}\big( -1 + \sqrt{1+8\left( \tfrac{k(k+1)}{2} - n +1\right)}\big) \right\rfloor.$$
My first question is:
Who is this formula due to?
I tried to prove it by induction but it gets messy pretty quickly.
How would you prove it?
The idea itself is simple : start from the end of the $\,\frac{k\,(k+1)}2\,$ terms and consider the complementary to $k+1$ of each term to get the sequence :$$\tag{0}\underbrace{1}_1,\underbrace{2,2}_2,\underbrace{3,3,3}_3,4,\cdots,\underbrace{k,k,k,\ldots, k}_{k\,\text{terms}}$$
Let's observe that the values in each sub-bloc will be $n$ only if the index belongs to $(T_n,T_{n+1}]$
with $\,T_n:=1+2+3+\cdots+n=\dfrac {n\,(n+1)}2\;$ the $n$-th "Triangular number".
The trick (found by Euler? See Triangular number and the Wikipedia reference $6$...) is to reverse $T_n=\dfrac {n\,(n+1)}2$ to get : $$8\,T_n=4n^2+4n=(2n+1)^2-1$$ and the expression for $n$ in function of $\,T_n\,$ : $$\tag{1} n=\frac{\sqrt{8\,T_n+1}-1}2$$ At this point we have to be careful because the value $n$ should be obtained for every index $i$ belonging to $(T_n,T_{n+1}]\,$ that we will rewrite as $\;(i-1)\in[T_n,\,T_{n+1})\,$.
From $(1)$ and the fact that the upper bound $\,\displaystyle n+1=\frac{\sqrt{8\,T_n+1}+1}2\,$ will not be reached (since $\,i-1<T_{n+1}$) we deduce the correct formula for $n$ in function of the index $i$ in $(0)$ : $$\tag{2} n=\left\lfloor\frac{\sqrt{8\,(i-1)+1}+1}2\right\rfloor$$
It remains to reverse the initial process :
to conclude : $$\tag{3}L_k(i) = k+1 - \left\lfloor \tfrac{1}{2}\left( 1 + \sqrt{1+8\left( \tfrac{k(k+1)}{2} - i\right)}\right) \right\rfloor.$$ (correcting a little your initial formula possibly obtained using the floor of $(1)$...)
ADDITION2: Instead of applying the floor function to $(1)$ we could have considered the ceil function and obtained more directly : $$\tag{2'} n=\left\lceil\frac{\sqrt{8\,i+1}-1}2\right\rceil$$ (this means that after replacing the floor by the ceil function your expression will become correct !)
ADDITION: OEIS A002024 has a simpler formula for $(2)$ with some interesting references : $$\tag{2''} n=\left\lfloor\sqrt{2\,i}+1/2\right\rfloor$$ that should provide a shorter answer than $(3)$ and that... I'll let you prove ! :-)