TITLE: A discrete math riddle
QUESTION [56 upvotes]: Here's a riddle that I've been struggling with for a while:

Let $A$ be a list of $n$ integers between 1 and $k$. Let $B$ be a list of $k$ integers between 1 and $n$. Prove that there's a non-empty subset of $A$ and a (non-empty) subset of $B$ having the same sum.

Example: Say $n=3,\ k=5$, and $A=\{3,4,5\},\ B=\{1,1,2,3,3\}$. Then we can find $\{1,3,3\}\subset B$ and $\{3,4\}\subset A$ with the same sum (I know there're are simpler solutions in this example, it's just for demonstration).
I tried to attack it from different directions: induction, pigeon-hole, combinatorics, but I couldn't make it work. Suggestions?

Addition
As this was so highly voted, I thought I should tell how I came about this riddle - it's an interesting story: I heard it from a friend of mine about 10 years ago when I just finished high school and he just graduated in math. I remeber him telling me the riddle and his solution, and I thought "math is so cool, some day I'll also have a degree in math and will be able to solve riddles like this". I don't know why I suddenly remembered this conversation, and why I remember only the problem and not the solution. but it turns out that now I have a degree, but I still can't.

REPLY [3 votes]: I've done this problem in my exam today. It's a nice problem and here is my solutuion:
First, I denote $A=\{x_1,x_2,...,x_n\}$, $1\leq x_1\leq x_2\leq ...\leq x_n\leq k$ and $B=\{y_1,y_2,...,y_k\}$, $1\leq y_1\leq y_2\leq...\leq y_k\leq n$.
Set $a_p=\sum_{i=1}^{p}x_i$ ($1\leq p\leq n$) and $b_q=\sum_{j=1}^{q} y_j$ ($1\leq q\leq k$).Without lost of general I can assume that $a_n\leq b_k$. From that, $\forall 1\leq p\leq n$, there exists $1\leq f(p)\leq k$ is the smallest index that $a_p\leq b_{f(p)}$. 
$$b_{f(1)}-a_1;...;b_{f(n)}-a_n$$
I comment that all $b_{f(i)}-a_i<n$ (if $n\leq b_{f(p)}-a_p$ with some $p$ $\rightarrow n<b_{f(p)}\rightarrow f(p)>1$, so we have $n\leq b_{f(p)-1}+y_{f(p)}-a_p\rightarrow 0\leq n-y_{f(p)}\leq b_{f(p)-1}-a_p\rightarrow a_p\leq b_{f(p)-1}$ (contradiction because I choose $f(p)$ is the smallest index))
If $b_{f(p)}-a_p=0$ with some $p$, I have the proof, if not, by the pingeonhole principle, we have $b_{f(r)}-a_r=b_{f(s)}-a_s$ with some $1\leq r< s\leq n$
$$\rightarrow b_{f(s)}-b_{f(r)}=a_s-a_r$$
$$\rightarrow \sum_{i=r+1}^{s}x_i=\sum_{j=f(r)+1}^{f(s)}y_j$$
So i have the proof.
(do i have mistake in somewwhere?)