Solution:
Let max{a1,a2}⩽a3⩽a4. Denote a2=β2 and a3=γ2,β,γ⩾0. From the condition of the problem it follows that a1⩽(γ−β)2 and a4⩾(γ+β)2.
Suppose that both of these inequalities are in fact equalities. Then we have a12+a22+a32+a42=3(β4+4β2γ2+γ4) and a1a2+a1a3+a1a4+a2a3+a2a4+a3a4=3(β4+β2γ2+γ4). Moreover γ⩽2β, so
β4+β2γ2+γ4β4+4β2γ2+γ4=1+β4+β2γ2+γ43β2γ2=1+1+γ2β2+β2γ23⩾711
with equality for γ=2β. Therefore, in this case we have K⩾711, and equality is attained for a1:a2:a3:a4=1:1:4:9.
Let us also show that we can take a1=(γ−β)2 and a4=(γ+β)2. Consider the expression
F=a12+a22+a32+a42−711(a1a2+a1a3+a1a4+a2a3+a2a4+a3a4)
For fixed a2,a3,a4,F is a decreasing function of a1 for a1<1411(a2+a3+a4), where 1411(a2+a3+a4)⩾1411(β2+γ2+(β+γ)2)⩾(γ−β)2⩾a1, so F does not increase if we replace a1 with (γ−β)2. Now we may assume without loss of generality that a1⩽a2, i.e. β⩽γ⩽2β. Similarly as above, for fixed a1,a2,a3,F is an increasing function of a4 for a4>1411(a1+a2+a3), and moreover 1411(a1+a2+a3)⩽1411(β2+γ2+(γ−β)2)⩽(γ+β)2⩽a4, hence F does not increase if we replace a4 with (γ+β)2.