Combinatorial puzzle reminiscent of knapsack problem. Is this classic?

Yes, it's a "classic problem" in pigeonhole principle for olympiad problems.

Proof by contradiction. Suppose not. Without loss of generality, $ \sum a_i > \sum b_i $.

Define $f(k)$ to be the smallest value $j$ such that

$$ \sum_{i=1}^j a_i > \sum_{i=1}^k b_i$$

Note that the difference between these partial sums $ \sum_{i=1}^{f(k)} a_i - \sum_{i=1}^k b_i $ is in the set $\{1, 2, \ldots , n-1\}$, since it is not 0, and it is capped by $a_j-1$. (Use the fact that $ \sum_{i=1}^{j-1} a_i < \sum_{i=1}^k b_i$)

By pigeonhole principle, since there are $n$ differences but only $n-1$ possibilities, thus there exists 2 differences that are identical. IE

$$ \sum_{i=1}^{f(k)} a_i - \sum_{i=1}^k b_i = \sum_{i=1}^{f(l)} a_i - \sum_{i=1}^l b_i $$

Now, take the differences of the partial sums, and they will have the same sum. IE (with $k>l$)

$$ \sum_{i=f(l) + 1}^{f(k)} a_i = \sum_{i=l+1}^k b_i $$


This also proves the observation that it is sufficient to consider subintervals.

This also shows why the condition of $1 \leq a_i \leq n$ is the best possible, with obvious counterexamples if we relax the condition further.

Putnam 1993 has a similar problem, with a similar solution that you are welcome to find.

Let $x_1, \ldots , x_{19}$ be positive integers less than or equal to 93. Let $y_1, \ldots , y_{93}$ be positive integers less than or equal to 19. Prove that there exists a (nonempty) sum of some $x_i$’s equal to a sum of some $y_i$’s.