Problem

You are given two integer arrays \(A\) and \(B\), such that \(|A| = n\) and \(|B| = m\). Further all elements of \(A\) are in the range \([ 1, \cdots, m ]\) and all elements of \(B\) are in the range \([ 1, \cdots, n ]\).

Prove that there exist non-empty subarrays of \(A\) and \(B\) that have the same sum.