#P3584. [POI 2015 R1] 贪吃鬼 Gluttons
[POI 2015 R1] 贪吃鬼 Gluttons
Description
There are dishes placed around a round table, forming a circle. The -th dish contains calories. Between every pair of adjacent dishes sits one person, so there are people in total. Each person can choose to eat either the dish on their left or the dish on their right. If two people choose the same dish, they split it equally, and each receives half of that dish’s calories. If a person can obtain strictly more calories than before by changing only their own choice (while the choices of the other people remain unchanged), then that person is dissatisfied. Please assign which dish each person should eat so that everyone is satisfied.
Input Format
The first line contains an integer , the number of dishes (which is also the number of people; both dishes and people are numbered from to ).
The second line contains integers . We stipulate that for person (), the dish on the left is dish , and the dish on the right is dish ; for person , the dish on the left is dish , and the dish on the right is dish .
Output Format
If no such assignment exists, output a single line NIE.
If such an assignment exists, output one line with integers, where the -th integer is the index of the dish chosen by person . If multiple valid assignments exist, output any one of them.
5
5 3 7 2 9
2 3 3 5 1
Hint
Constraints
For all testdata, , .
Original title: Łasuchy.
Thanks to @KSkun for providing the SPJ for this problem.
Translated by ChatGPT 5
京公网安备 11011102002149号