I am trying to solve the following problem on integer sequences and subset sums from a 2023 Shanghai high school entrance exam:
Let $A = (a_1, a_2, \dots, a_n)$ be a sequence of positive integers such that $$ \sum_{i=1}^n a_i = 2013 $$ Find the minimum value of $n$ such that every possible sequence of length $n$ satisfying the sum constraint contains a consecutive sequence of elements whose sum is exactly $31$ (e.g., $a_4 + a_5 + \dots + a_{10} = 31$).
Allegedly, fewer than 100 students managed to solve this problem rigorously.
Latest progress (what we need now)
While we have found a construction for $n=1021$, and proved $n=1021$ isn't ok, I am looking for a rigorous proof that $n=1022$ is the minimum. Specifically:
(Solved) Prove for every $n<1022$ that there exists a sequence that doesn't satisfy the condition [contains a consecutive sequence of elements whose sum is exactly $31$].
How do I rigorously prove that any sequence of length $1022$ with sum $2013$ must contain a consecutive sum of $31$?
My first thought
I suspect we need to analyze the "worst-case scenario"—that is, constructing a sequence that avoids having a subset sum of $31$ with the maximum possible length. If I can find the maximum length $n_{\max}$ that fails the condition, then the answer should be $n_{\max} + 1$. Intuitively, to maximize the length of the sequence without reaching the total sum too quickly, we need small numbers. I think we need many occurrences of $1$ in this sequence, but we can't have thirty-one $1$s, for otherwise the sum $31$ is trivial. How do I formalize the construction of the sequence that avoids $31$ to find the threshold?