COCI '25 Contest 1 #2 Krugomet
View as PDF
students gathered in the schoolyard one sunny day and stood in a large circle. Each person had his own box of balls (person
has
balls), as well as his crush (maybe even himself), denoted by
.
They decided to play their favorite game, krugomet. Playing krugomet consists of rounds. In each round, all participants in the game simultaneously throw all their balls towards their crush. The students are skilled and agile, so they will always catch all the balls thrown to them in a round. After the balls are caught, everyone gets ready for the next round, and the whole process is repeated.
The teacher fell asleep on the bench and left the students to play alone. When he woke up, the students asked him to tell them who won, i.e. to answer questions:
- How many balls does the student with the most balls have after
rounds of play?
- Who collected the most balls after k rounds of play?
The teacher knows how many students played krugomet , the sequence of crushes
, the initial number of balls for each student
, and how many rounds of play
were played. Unfortunately, the teacher doesn't have time to count how many balls each person has, so he leaves that up to you.
Help him and determine the list of students who collected the most balls. In case there is more than one person with the most balls, print their indices in order from smaller to larger.
Input Specification
In the first line are the two natural numbers and
from the text of the task.
In the second line, there are natural numbers
, numbers from the text of the task.
In the third line are n natural numbers
, numbers from the text of the task.
Output Specification
In the first line, print a single number - the number of balls collected by the student with the most balls.
In the second line, print the indices of the students who collected the most balls. The indices should be printed in ascending order.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| The sequence s is a permutation, |
||
| No additional constraints. |
Correctly printing the st line earns
points for the test example. The remaining
points for the test example are earned by correctly printing the
nd line.
Sample Input 1
2 1
5 6
2 1
Sample Output 1
6
1
Explanation for Sample Output 1
In the only round of krugomet, people labeled and
threw all their balls towards each other and "swapped" how many balls each person had. After the first round, person labeled
had the most balls and was holding
balls.
Sample Input 2
4 2
5 5 5 5
1 2 1 1
Sample Output 2
15
1
Sample Input 3
4 10000000
1 2 3 4
2 1 4 3
Sample Output 3
4
4
Comments