Request for solution of atcoder beginner contest 44 problem C

Hello Community,
Can anyone kindly explain the solution for the C problem of atcoder beginner contest 44? The problem name is Tak and Cards. The editorial is present in japanese. Doing google translation of the editorial is not making much sense to me. I believe the community can explain to me the solution in a better manner. I realise that the problem can be solved using both 2d DP and 3d DP as I could make out from the japanese editorial but I need further help from there.

Thanks in advance…