Official

E - Cut in Half Editorial by en_translator


This problem can be solved by performing binary search for the answer.

First, consider the following problem:

Problem 1: a bag contains a stick of length \(A\). How many operations are needed to make the all stick lengths \(D\) or less?

Since the stick length always takes the form \(\frac{A}{2^k}\), the answer to the problem is \(2^k-1\), where \(k\) is the minimum integer with \(\frac{A}{2^k}\leq D\).

Problem 2: a bag contains \(N\) sticks of lengths \(A_1,\ldots,A_N\). How many operations are need to make all the stick lengths \(D\) or less?

This can be answered by solving Problem 1 for each stick independently.

Problem 3: a bag contains \(N\) sticks of lengths \(A_1,\ldots,A_N\). How long is the longest stick after \(K\) operations?

This is boiled down to Problem 2 by using binary search.

Problem 3: a bag contains \(N\) sticks of lengths \(A_1,\ldots,A_N\). How long is the \(X\)-th longest stick after \(K\) operations?

We first solve Problem 3 to determine what length each stick has become. Since here can be at most \((N+1)\) different lengths after the operations, the answer can be found by counting sticks of each length.

All numbers appearing in the process can be precisely represented as a 64-bit floating point number, without an error.

posted:
last update: