Problem Link - Task_D
hello everyone, here’s the problem I have been trying to solve.
If you’ve read the problem here’s my thinking process,
The piece that we want to move will start at any place we want. At first, let say we are at position x now I am moving that piece to pos[x] here pos is permutation given. now we will continue walking in this manner until we find a cycle
Now for all possible positions of X from which we start from there will be one cycle. So we’ll find all these cycles starting at every position
for i = 1 to N
I was only able to think till here after trying, then for the further hint, I asked my doubt on cf and I got this answer. what I can understand from that is,
I’ll solve all of these cycles individually. Now, for each cycle, I can take atmost K nodes and try to make my sum (profit) maximum. So I guess this problem can be broken down to this problem.
Now i can not understand it furthure how to solve each cycle using this method. i can not understand how we are maximizing the profit in terms of K and length of cycle . In this comment a few lines at the end explain that logic but still, I can’t get it. Any help in completely understanding this logic will help me a lot.