Good morning everybody.
January Clash '16 will start tomorrow (check your time zone). Duration is 24 hours and submitting time doesn't matter so you can join whenever you want.
Note the unusual starting time (compared to previous Clashes). We moved it a bit because of colliding with Facebook Hacker Cup.
You will be given 5 algorithmic problems and one approximate (optimization) one. All problems will have partial scoring (points for each test passed) and easier subtasks. Thus, everybody should find something for themselves. Getting full points on all 5 problems should be hard for everyone. Remember to solve as many subtasks as possible if you want to get to the top.
Problems were prepared by Lewin. He is an author of numerous contests, including many SRM's on TopCoder (link) so you don't have to worry about the quality of the problem set. I am a tester and an editorialist.
Problems are interesting and so do smaller subtasks. Don't expect them to be very easy though — some of them are far from being straightforward. Anyway, solve them first if you don't see a 100-points-solution.
There are prizes — t-shirts and Amazon gift cards. And the eternal glory of course.
Enjoy a contest.
WINNERS
Congratulations:
I want to congratulate anta for solving the hardest problem and Egor for almost solving it — but well, he won anyway. Kostroma had the best score in an approximate problem and HellKitsune was very close to that.
What was your approach to an approximate problem?








values to consider because we don't care about numbers much larger than
. The answer will be equal to the sum of values of
. Creating an additional array with prefix sums will allow us to calculate such a sum in
.
. The explanation isn't complicated. We can't be faster than
because we fight at most two criminals in each hour. And maybe e.g.
where every sum denotes the sum over
possible divisions.
and then we will get
(this is what we're looking for).
.
then we should increase
ways to divide numbers into two groups. For fixed division of numbers and for fixed position of the smallest number in
for all
so it's enough to add
to the result. There is
. Don't be misled by words "simple to calculate". It took me literally weeks to solve this problem and I don't say that it is easy to find the formula above.
. You can find my code above.
and 



times multiplying matrices
.
solution. We divide a sequence into
Parts. When choosing the best candidate in a Part, we want to forget about other Parts. It's enough to remember only
and then construct new hull for this Part in
from complexity. First, binary search can be replaced with pointers — for each Part initially we set a pointer at the beginning of Part. To find best candidate in Part, we slowly move pointer to the right (by one). Complexity is amortized
. And we can sort linear functions
. Note that when rebuilding a hull, we must set pointer to the beginning of Part.
. 
