Codeforces 1183D. Candy Box (easy version) Codeforces Round #570 (Div. 3)


Problem link

Let's calculate the array cnt where cnti is the number of candies of the i-th type. Let's sort it in non-ascending order.

Obviously, now we can take cnt1 because this is the maximum number of candies of some type in the array. Let lst be the last number of candies we take. Initially it equals cnt1 (and the answer ans is initially the same number). Then let's iterate over all values of cnt in order from left to right. If the current number cnti is greater than or equal to the last taken number of candies lst then we cannot take more candies than lst−1 (because we iterating over values of cnt in non-ascending order), so let's increase answer by lst−1 and set lst:=lst−1. Otherwise cnti<lst and we can take all candies of this type, increase the answer by cnti and set lst:=cn

A solution in c++


Post a Comment

0 Comments