K piles stone game

1.4k Views Asked by At

Their are k piles with total n stones in some order where each pile can have stones greater or equal to zero.Two player A and B plays a game in which player A cant see the configuration of piles but he knows the size of each pile only order is unknown to him.Player A points to a pile and Player B removes one stone from that pile.

If their is no stone in that pile player B informs player A that this pile is empty.

Now the Player A wants atleast C stones in minimum moves.I want to find the minimum moves P so that Player A gets atleast C stones after P moves whatever be the initial configuration of piles.

Like if we have three piles and six stones and player A needs to get four of them . Then minimum moves required to get 4 stones is 4.

1

There are 1 best solutions below

24
On BEST ANSWER

Edit: My original answer was based on a misunderstanding of the problem and was actually wrong even for that interpretation. The problem as it now stands seems somewhat difficult. This is not an answer, and I may end up deleting it, but it does include some ideas that may be useful and shows why a complete answer may be a bit complicated, so I’ll leave it up for now.

Suppose that the piles have $a_1,a_2,\ldots,a_k$ stones, where $a_1\le a_2\le\ldots\le a_m=\ldots=a_k$. If $C\le a_1$, then of course Player $A$ will need only $C$ moves. It’s also clear that if $m=1$, so that all piles are the same size, Player $A$ will need only $C$ moves. Suppose that $m>1$ and $C>a_1$. In the worst case Player $A$ picks the smallest pile $a_1+1$ times and collects $a_1$ stones. If $m=2$ or $C\le a_1+a_2$, he need not make any more bad moves, so he can collect $C$ stones in $C+1$ moves. If $m>2$ and $C>a_1+a_2$, he could make $2$ bad moves in collecting the first $a_1+a_2$ stones. If $m=3$ or $C\le a_1+a_2+a_3$, he need not make any more bad moves, so he can collect $C$ stones in $C+2$ moves.

Let $b_0=0$, and for $i=1,\ldots,k$ let $b_i=a_0+\ldots+a_i$. Suppose that $b_i<C\le b_{i+1}$; if $m>i$, Player $A$ could make $i$ bad moves in collecting the first $b_i$ stones and therefore need altogether $C+i$ moves to collect $C$ stones. However, he never needs more than $m-1$ bad moves to reach a position in which all piles are the same size, so he actually needs at most $$C+\min\{m-1,i\}$$ moves to collect $C$ stones. For fixed $n,k$, and $C$, therefore, we want to choose $a_1,\ldots,a_k$ so as to minimize $\min\{m-1,i\}$, where $i$ is the unique index such that $b_i<C\le b_{i+1}$.