We are basically given $n$ piles of size $a_i$, $1 \leq i \leq n$. Each pile has $1 \leq a_i \leq 10^3$ items, and collectively all piles have $1 \leq \sum_{i=1}^{n} a_i \leq 10^6$. All we care about is the fact that there are no more than one million items, each of which belongs to a pile (indexed as given). We then get $m$ queries that ask: What pile is $x$ in?
So we're going to just build an inverse lookup table as we read in the pile sizes, and do a constant-time lookup operation for each query.
It's interesting to compare the execution statistics between different language implementations. Often we find exactly what we expect: C++ is much faster. But that doesn't mean you shouldn't use Python at all, since coding time becomes a critical factor in competition.