I have used segment tree for range minimum query. And for each of the query I choose the actual range of cans which can be choosen. I got 70 points and WA in one of the test cases of 30 points.
So, is the test cases weak for the second subpart or I have missed something ?