Inspired by a friend Zijing Ou, here is an easy solution by constructing a mask:
mask = torch.linspace(0, t.shape[1]-1, t.shape[1]).view(1, t.shape[1]).repeat(t.shape[0], 1) < c.view(t.shape[0], 1)
(t * mask).sum(1)

would get the desired results.