Now I have a solution:
t.cumsum(1)[torch.arange(len(c)), c-1]
tensor([4.0000, 8.5000])

But it does not work if c[i] is 0 for any i. And it does a lot of redundant calculation in the cumsum(). So maybe there is a better solution?