Distribute Gifts among students $N$ students are to be provided with gifts We know that the $i$'th student wants to get at least $a_i$ gifts.
The teacher wants to give distinct gifts meaning if he give $x$ gifts to one student then he will not give $x$ gifts to any other student and on the other hand, the total sum of the gifts must be as small as possible.
How to solve this problem
let if their are $3$ students who wants atleast $\{5,1,1\}$ gifts.Then answer is $5$, $1$, $2$.
Note : I need to find most optimal solution
 A: You can solve this problem with a greedy algorithm. Give to student $1$ $a_i$ gifts. And then to student 2 the minimum number of gifts you can give. So if a_2=a_1 then give him $a_2+1$ In general give to student $a_k u_k$ gifts: where $a_k\leq s_k$ and $s_k\neq s_i$ for $i<k$ 

The arrangements are going to be of the following way: Take you list $(a_1,a_2,a_3\dots a_N)$ and order it to get $(b_1,b_2,b_3,\dots b_N)$. So that they are the same number but ordered.Then we make the following partition. Let $i<k$. In general $a_i$ and $a_k$ are in the same partition if $a_k-a_i< k-i$. Now we can see that the best distributions are going to be of the following way: For each partition let $b_x$ be the smallest $b$ in that partition. Then you give $b_x$ exactly $b_x$ presents and give $b_{x+1}$ exactly $b_{x+1}$ presents and so on until you give a present to every one in that partition. And do that for all the partitions.Suppose that the list was partitioned into sets $p_1,p_2\dots p_m$ then the minimum number of presents will be $\sum_{k=0}^Nb_k+\sum_{k=0}^m(|p_k|-1)$
A: You can just start with $x=1$ gift. I there is anybody who accepts $1$ gift, give him $1$ and remove him from the list. Now set $x=2$ and search for someone who accepts two packages. If any body accepts two gifts, give him $2$ gifts and remove him from the list.
You can just continue to increase $x$ by one and try to give someone $x$ gifts, until all students have a gift.
A: Considering my poor understanding of the question, the least number of gifts for N number of students should be N(N+1)/2 as the least number of gifts given to a particular student would be 1 and maximum be N. (Sum of N natural numbers)
