luogu#P9294. [POI 2020/2021 R1] Cukiernia / 糕点店
[POI 2020/2021 R1] Cukiernia / 糕点店
Background
This problem is translated from XXVIII Olimpiada Informatyczna – Stage I Cukiernia。
Problem Description
The Bajtuś bakery sells three kinds of food: cakes, donuts, and croissants. In the bakery, there are display shelves. Under normal conditions, each shelf should contain only one kind of food. But one morning, the bakery owner Bajtazara’s son Bajtuś sneaked into the bakery and messed up all the food placement.
The bakery is about to open. Bajtazara urgently wants to rearrange the food so that each shelf contains only one kind of food (in particular, it is also allowed for a shelf to be empty). Please help him find the minimum number of moves needed to achieve this goal.
Input Format
The first line contains an integer , representing the number of shelves in the bakery.
The next lines each contain three integers , representing the current number of cakes, donuts, and croissants on the -th shelf. The testdata guarantees that there is at least one piece of food in the bakery.
Output Format
Output one integer, the minimum number of moves required to move the food.
5
5 1 1
0 3 4
1 4 3
4 0 0
0 0 0
9
3
1 1 2
2 1 1
1 1 2
7
5
5 5 5
5 5 5
5 5 5
5 5 5
5 5 5
50
Hint
[Sample Explanation #1]:
One valid moving plan is as follows:
- Move one donut from shelf to shelf , and move one croissant from shelf to shelf .
- Move three donuts from shelf to shelf .
- Move one cake from shelf to shelf , and move three croissants from shelf to shelf .
After that, shelf contains only cakes, shelf contains only croissants, shelf contains only donuts, shelf contains only cakes, and shelf is empty.
[Constraints]:
All test points satisfy: , .
| Subtask ID | Score | |
|---|---|---|
Translated by ChatGPT 5