I was trying to solve [problem](http://www.spoj.com/problems/COT2/). In this problem, the constraint for weight is not given.↵
So i assumed it to be less than 1000000 and solved it accordingly. Here is my [code](https://ideone.com/GVvY2q). But it is giving RE. I have wasted a whole day to rectify it but i couldn't. Please someone help me.↵
**EDIT**: I used set in place of array to store weight. So, there should not be any case of overflow.But still getting RE with [code](https://ideone.com/XayVRl).
So i assumed it to be less than 1000000 and solved it accordingly. Here is my [code](https://ideone.com/GVvY2q). But it is giving RE. I have wasted a whole day to rectify it but i couldn't. Please someone help me.↵
**EDIT**: I used set in place of array to store weight. So, there should not be any case of overflow.But still getting RE with [code](https://ideone.com/XayVRl).