시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 512 MB 13 4 3 25.000%

문제

The most adventurous part of skiing is the journey onto the mountain-top, between trees and through clouds, and past all sorts of enchanting views.

Naturally, the skiers at the foot of the lift can hardly wait to take their turns (although they are a little disappointed that the climb will eventually terminate). They all know exactly which times they plan to catch a lift on the tireless rotary machine.

Unfortunately, there are only so many gondolas available at the start of the day to attach to the track loop. The track loop takes 2 · T minutes to cycle around (T on the way up and then T on the way back down). Given that you can arrange the gondolas on the track however you see fit, what is the minimum summed waiting time of all skiers that you can achieve?

입력

  • One line containing three integers:
    • N (1 ≤ N ≤ 400), the number of skiers.
    • T (1 ≤ T ≤ 720), the time to travel from the bottom of the hill to the top in minutes.
    • G (1 ≤ G ≤ 400), the number of available gondola cabs.
  • A further N lines in no particular order, each containing one integer X (0 ≤ X ≤ 106) which gives the time when a skier arrives at the foot of the mountain.

출력

  • One line containing one integer: the minimum possible sum of all waiting times, where the waiting time for one skier is the time difference between their arrival and departure on the next available gondola (which may be shared with any number of other skiers).

예제 입력 1

4 10 2
0
15
30
45

예제 출력 1

10

예제 입력 2

4 10 3
0
15
30
45

예제 출력 2

5

예제 입력 3

5 16 3
16
7
5
8
1

예제 출력 3

4

힌트