I have used the following approach but it is getting me a WA. Please help me out if you can.
- Sorting the elements in descending order while the friends in ascending order.
- distributing elements (highest to lowest) one by one among friends.
ex: E: 7 7 6 6 3 2 1| F: 1 1 2 3
distribution: (7) — — -| (7) (7) — -| (7) (7) (6) -| (7) (7) (6) (6)| (7) (7) (6,3) (6)| (7) (7) (6,3) (6,2)| (7) (7) (6,3) (6,2,1)|
Under which testcase will this give a wrong solution
try this test case
7 3
7 6 6 3 2 1 1
1 3 3
your approach will produce
7
6 3 1
6 2 1
Your ans = 28
But we can also arrange like this —
7
6 3 2
6 1 1
Ans = 29