Say, that there is a group of $n$ people who decides to share Christmas gifts.
Each person has a budged, he/she will spend at most $m\_i \in \mathbb{Q}$ coins on gifts.
Each person must give, exactly $1\leq g\leq n-1$ gifts,
and each person must receive $g$ gifts. Furthermore, the total worth $w$ of gifts received must be 
equal for each person. How do one maximize $w$?


Clearly, if $g=n-1$ then each person $i$ will give a gift of value $m\_i/(n-1)$ to every other person. Thus, $w$ is the arithmetic mean of the $m\_i$:s.
However, if $g=1,$ then every person cannot give more than $\min\_i m\_i$
so $w=\min\_i m\_i$ in this case.


The case when all $m\_i$ are equal is also simple, just give $g$ gifts of value $w=m\_i/g$
so that everyone receives $g$ gifts, and $w$ is maximized.


However, what can be said in the general case? Is this equivalent to some known problem, like knapsack or max-flow?


As a graph-theoretical problem, one may view this as a directed 2g-regular graph, on $n$ vertices, where each vertex has out-degree g. Each vertex is a source and a sink, and one wants to maximize the flow so that all sinks receive the same amount.



Christmas giftgiving
In the graph theoretic setting, the question is analyzed by N. Megiddo in 


Optimal flows in networks with multiple sources and sinks (1973) (google will give you the pdf). Gives an algorithm, does not seem to discuss complexity)


More recently this is discussed (in a more general setting) in the classic Ahuja/Mananti/Orlin, chapter 17. They do discuss complexity, but you have to hunt around a bit.


