Podjela
The farmer's guild produced a certain amount of grain and delivered it to a large food company. The food company paid each of N farmers the same amount X. The farmers know that they did not all do the same amount of work so they want to redistribute the money they got more fairly. The farmers all live in different villages. Villages are connected by roads so that there is a unique way to get from one village to every other. In a single transaction one farmer uses his tractor to visit a village neighbouring his own and hands any amount of money to the farmer living there. For each farmer we know the amount he deserved. Your program must determine:
a) The smallest number of transactions for every farmer to get the amount he deserved.
b) The transactions themselves, in the correct order. When determining the order of transactions, keep in mind that a farmer cannot give an amount of money larger than he currently has.
It is possible that the food company overpaid the farmers (paid more than the farmers ask for). In such a case, the farmers don't care how the excess money is distributed, as long as each of them gets at least as much as he deserved.
]. These mean that the farmer from village A travels to village B and hands C units of money to the farmer living there. There must be a road connecting villages A and B. The transactions and their order may not be unique. [c]5
1
0 2 2 0 1
1 2
1 3
3 4
3 5
Output:
2
1 2 1
4 3 1Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.