• + 5 comments

    It is not clear why input
    10 7
    0 2
    1 8
    1 4
    2 8
    2 6
    3 5
    6 9
    should give the answer 23. We have 2 groups: {0 1 2 4 6 8 9} and {3 5}. So, it should be 14.