Help with approach

problem: https://codeforces.com/problemset/problem/1472/B

sol: https://ide.codingblocks.com/s/402832

only 1 test case is passing

Have you gone through the editorial and the code for the given there.
try to check if that you can relate with yours.

yes checked , I can’t relate it if I could I wound’t be posting here

@raghav007 check this :
i have commented everything:


if you stil have any doubt you can ask here.
Happy Learning!!

why is cnt2 multiplied by 2?

because there we are calculating the sum there:
if there are total 5 candies like this: 1 1 2 2 2
total 2 weight candies are : 3 (cnt2)
total 1 weight candies are : 2 (cnt1)
so the sum is cnt1+2*cnt2=8.
got it?
if you still have any doubt you can ask here;
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.