아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Metal Harvest

면접 대비

시간 제한20초메모리 제한1024 MB

요약
겹치지 않는 시간 구간들과 최대 배치 시간 K가 주어질 때, 모든 수확 시간을 채우는 데 필요한 최소 로봇 배치 횟수를 구한다.
난이도

보통10점 중 4점

유형
그리디, 구간
정답자
아직 제출이 없습니다

문제

You are in charge of deploying robots to harvest Kickium from a nearby asteroid. Robots are not designed to work as a team, so only one robot can harvest at any point of time. A single robot can be deployed for up to K units of time in a row before it returns for calibration, regardless of how much time it spends on harvesting during that period. Harvesting can only be done during specific time intervals. These time intervals do not overlap. Given K and the time intervals in which harvesting is allowed, what is the minimum number of robot deployments required to harvest at all possible times?

입력

The first line of the input gives the number of test cases, T. T test cases follow.

The first line of each test case gives two space separated integers N and K: the number of time intervals in which harvesting is allowed, and the maximum duration a robot can be deployed for before returning for calibration.

The next N lines contain a pair of space separated integers Si and Ei: the start time and the end time of the i-th interval respectively. Please note that intervals don't include the time unit starting at the moment Ei, so for example an interval with (Si = 2; Ei = 5) has duration of 3 time units.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of times robot deployment is needed so that for each interval there is one robot harvesting at that time.

제한

  • 1 ≤ T ≤ 100.
  • All Si are distinct.
  • For any two intervals (Si,Ei) and (Sj,Ej) with Si < Sj, Ei < Sj.

힌트

In Sample Case #1, we deploy the robot at time instant 1 and it becomes available for the interval [1, 6]. However, it harvests only for the time range [1, 5]. After that we deploy the robot at 6 and it becomes available for the time interval [6, 11]. This deployment covers both the remaining intervals [8, 9] and [10, 11]. There are multiple optimal strategies here. For example, we can deploy the second robot at 7. It would then cover the range [7, 12], thus harvesting for the intervals [8, 9] and [10, 11].

In Sample Case #2, we deploy the robot at time instant 1, and it becomes available for [1, 3], but harvests for [1, 2] as [2, 3] is not part of any interval. After that we deploy the robot at 3 for the time range [3, 5] in which the robot harvests for the interval [3, 5]. The third deployment is done at time instant 13 making the robot available for time range [13, 15]. However, it harvests only for the interval [13, 14]. Thus three deployments are needed to cover all the intervals.

예제1

  1. 예제 1

    입력
    2
    3 5
    1 5
    10 11
    8 9
    3 2
    1 2
    3 5
    13 14
    
    예상 출력
    Case #1: 2
    Case #2: 3