The last act of the IOI 2015 opening ceremony is in progress. During the opening ceremony, each team was supposed to receive a box with a souvenir from the host. However, all volunteers are so fascinated by the ceremony that they completely forgot about the souvenirs. The only person who remembers about the souvenirs is Aman. He is an enthusiastic volunteer and he wants the IOI to be perfect, so he wants to deliver all the souvenirs in the least amount of time.
The venue of the opening ceremony is a circle divided into
There are
At any moment, Aman can only carry at most
Your task is to find the smallest number of seconds Aman needs to deliver all souvenirs and then return to his initial position.
Example
In this example we have
One of the optimal solutions is shown in the picture above. In his first trip Aman takes two souvenirs, delivers one to the team in section 2, then the other to the team in section 5, and finally he returns to section 0. This trip takes 8 seconds. In his second trip Aman brings the remaining souvenir to the team in section 1 and then returns to section 0. He needs another 2 seconds to do this. Thus, the total time is 10 seconds.
Task
You are given
long long delivery(int N, int K, int L, int positions[])
- This function will be called by the grader exactly once.
N
: the number of teams.K
: the maximum number of souvenirs Aman can carry at the same time.L
: the number of sections in the venue of the opening ceremony.positions
: an array of length .positions[0]
, ...,positions[N-1]
give the section number of all teams. The elements of positions are in non-decreasing order.
The function should return the smallest number of seconds in which Aman can complete his task.
Subtasks
subtask | points | |||
---|---|---|---|---|
1 | 10 | |||
2 | 10 | |||
3 | 15 | |||
4 | 15 | |||
5 | 20 | |||
6 | 30 |
Comments