Distribution Problem

I am finding trouble programming a question, which is:

Q. There a N children, among which k children have x sandwiches and (N-k) children don’t own a sandwich. We have to finish the number of sandwiches as fast as possible using 2 operations:

  • Take only 1 children and distribute y sandwiches to another children 1 < y <= x OR
  • every children that owns a sandwich will eat only 1 sandwich


4 <- children
1 2 1 2 <- child1 owns 1 sand, child2 owns 2 sand, child3 owns 1 and so on…

Result: 2
clock1: each children eats a sandwich
0 1 0 1
clock2: remaining also eats 1 sandwich
0 0 0 0

How do i implement this? gotta submit it by tommorow assignment… :confused:

A solution using bitmask dp can be easily found. Good luck!