#B3784. Concert Playlist Planning
Concert Playlist Planning
Concert Playlist Planning
In this problem, zyl is organizing a special concert for a festive occasion. She needs to plan the concert's setlist by selecting songs based on their "joy" values as gathered from her classmates. There are $$n$$ songs (numbered $$1\sim n$$) and zyl must choose $$m$$ of them. The class has $$a$$ students (excluding zyl), numbered $$1\sim a$$. For each song $$j$$ and each student $$i$$, the happiness value is given by $$h_{i,j}$$. The "joy" of a song is defined as the sum of happiness values from all $$a$$ students, i.e.,
[ J_j = \sum_{i=1}^{a} h_{i,j} \quad (1 \le j \le n) ]
It is guaranteed that for every student, the happiness values for different songs are distinct, and furthermore, no two songs share the same total joy (i.e. (J_j) are all unique).
Normally, zyl selects the top $$m$$ songs with the highest total joy and orders them in descending order of joy. However, zyl also considers her own happiness values for the songs. Her favorite song is the one that gives her the highest happiness value. The final playlist is adjusted as follows:
- If her favorite song is already in the selected list, it is removed from its original position and inserted at the beginning (while the relative order of the other songs remains unchanged).
- If her favorite song is not in the selected list, then the last song in the selected list is removed and her favorite song is appended to the end.
Your task is to output the final playlist by listing the song numbers in order.
inputFormat
The first line contains three space-separated integers: n
(number of songs), m
(number of songs to select), and a
(number of students excluding zyl).
The next a
lines each contain n
integers. The ith line contains the happiness values from student i for each song: hi,1 hi,2 ... hi,n
.
The last line contains n
integers which are zyl's happiness values for the n
songs.
Note: It is guaranteed that the total joy values \(J_j = \sum_{i=1}^{a} h_{i,j}\) for each song are all distinct, and that every student (excluding zyl) gives distinct happiness values for different songs.
outputFormat
Output the final playlist as m
space-separated integers representing the song numbers in order.
sample
5 3 2
4 8 12 16 20
6 12 18 24 30
25 35 45 15 5
3 5 4