Editorial for DMPG '19 G1 - Camera Calibration Challenge
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,This problem was greatly inspired by this DMOPC problem. The first subtask can be solved in the same manner as it.
For the remaining of points, we can take advantage of some monotonic properties. Observe that as
increases, the number of elements that become "clipped" monotonically increases.
Thus, we can push the elements in the grid into a queue in descending . We maintain the current sum
of non-clipped elements and the number
of clipped elements. For each query
, we want to find the first
such that
. Rearranging, we find that
. Let's call
our target sum,
.
We then process the queries in ascending . For each query
, we know that
must be at least
. However, setting
to this value may result in some of the values clipping and the true
being larger. Thus, as long as the elements at the front of the queue are clipped by our current
, we will pop them off and recalculate
,
, and
. Once we have found a
that does not clip any additional elements, we have our answer. As each of the
elements is popped at most once, the overall complexity of this stage is
.
However, there is one thing to watch out for. There are certain values for ,
, and the element at the front of the queue
such that when
is calculated, it is smaller than the previous
. (One such set of values from the test data is
,
, and
.) How is this possible if
is supposed to be monotonically increasing?
The problem lies with the ceiling function. In such cases, does not cause
to clip, but
does. This causes us to pop
off the queue and calculate
, which in these cases turns out to be less than
. However, since we needed
to be at least
in order to clip
, the correct answer would be
, not
! These cases are a common source of WA's but are easily dealt with by updating
to
rather than replacing it with
.
Time Complexity:
Comments