storing weight sum upto x - y point
if ( weight_at_x . ContainsKey ( new_x ) ) { weight_at_x [ new_x ] += w [ i ] ; } else { weight_at_x . Add ( new_x , w [ i ] ) ; } } List < int > sum_till = new List < int > ( ) ; sum_till . Add ( 0 ) ;