Given two sets; $X = \{x_i : x_i \geq 0; i \in [\sqrt{n}]\}$ and $A = \{a_i : |a_i| \leq 1; i \in [\sqrt{n}]\}$ of size $n^{\frac{1}{2}}$ each, with the following properties
\begin{equation}\label{eq1}
\sum_{i=1}^{\sqrt{n}}x_i \leq 1;
\end{equation}
\begin{equation}\label{eq2}
\left\lvert\sum_{i=1}^{j}a_i\right\rvert \leq 1; \forall 1\leq j \leq \sqrt{n}.
\end{equation}
Define $$f(X,A) := \min_{1\leq j\leq k \leq n^{\frac{1}{2}} } \left\{{\left(\sum_{i=j}^k {x_i}\right)^2} \times \left|\sum_{i=j}^k {a_i}\right|\right\}. $$
Also define $$f_n := \max f(X,A);$$ where the maximum is taken over all possible sets $X$, $A$ satisfying the properties. A trivial upper bound would be the following $$f(X,A) \leq \min_{1\leq j\leq k \leq n^{\frac{1}{2}} } \left\{{\left(\sum_{i=j}^k {x_i}\right)^2} \right\} \ll n^{-1};$$
where $a \ll b$ means there exists an absolute constant $\delta$ such that $a \leq \delta b$. Hence $$f_n \ll n^{-1}.$$
I am interested in finding non-trivial upper bound for $f_n$. For example something like $n^{-\frac{5}{4}}$ would be great.
This problem basically generated from a geometry problem I was trying. After using some Erdős–Szekeres type estimates I am stuck with this type of equation which I don't know how to estimate nicely. As the $a_i$'s can take negative values most inequalities I know of are not applicable.