While I was solving a problem on TopCoder I used the following assumption. I have n intervals: $ [a_1,b_1], [a_2,b_2],...,[a_n,b_n]$ and a number $T$ such that: $$ a_1 + a_2 + ... + a_n \leq T \leq b_1 + b_2 + ... + b_n $$
Then there is a choice of numbers $x_1,x_2,...,x_n$, with $x_i \in [a_i,b_i] $, such that: $$x_1 + x_2 + ... + x_n = T $$
For example, let's say I have to intervals: [1.6 , 2.3] and [1.7 , 2.7]. If T = 4.5 , with 1.6 + 1.7 < 4.5 < 2.3 + 2.7, then I have 4.5 = 2.2 + 2.3 , with 2.2 belonging to the first interval, and 2.3 to the second. The solution is not unique.
Now, I know that this the claim I stated is pretty obvious and intuitive. One can easily find a greedy algorithm that can find a choice of x's. We can start with $x_1 = a_1, x_2 = a_2, ... , x_n = a_n $, and then increment each x as needed to attain the $T$ value.
For example, I begin with T1 = 1.6 + 1.7 = 3.3. I didn't attain the T value! I look at the first x, and I try to increase it. T2 = 2.3 + 1.7 = 4.0. I haven't reached the T value and I can no more increase the first x. So I proceed to the second x. By increasing the second x to 2.2, I now have 2.3 + 2.2 = 4.5.
Intuitively this algorithm works every time. But how can I prove its correctness? Note that I don't have much experience in proving this type of claim. My 'common sense' got me to this statement. It would be great if somebody could show me how to prove it. Thank you!!
The set $[a_1,b_1]\times \ldots\times [a_n,b_n]$ is connected (as a product of connected sets) and hence the image under the continuous map $[a_1,b_1]\times \ldots \times [a_n,b_n]\to \mathbb R$, $(x_1,\ldots,x_n)\mapsto x_1+\ldots +x_n$ is connnected, so with $a_1+\ldots +a_n$ and $b_1+\ldots +b_n$ it attains also all intermediate points.