Блог пользователя pj_2103

Автор pj_2103, история, 23 месяца назад, По-английски

Their are n number of children each of which have a[i] number of toffees. You have k extra number of toffees, you have to distribute less than or equal to k no of toffees such that maximum number of children have equal number of toffees. You have to find out the maximum number of children that will have equal number of toffees after the distribution of the toffees.

Constraints : Time complexity less than or equal to O(n*log(n)).

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem source?

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

We can easily see that the number of toffees that the maximum number of children have is one of n original ai (toffees), so you just need to sort then use prefix sum or something similar.