Logo
(追記) (追記ここまで)

28482번 - Lifts 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2.5 초 64 MB0000.000%

문제

You have been hired to build a lift system for a hotel!

The hotel has $k$ lifts, and initially you can choose which floors they are on. During the day there are $n$ requests, each characterized by a pair $(l, r)$. This means someone is on the $l$-th floor and wants to go to the $r$-th floor.

People don’t like waiting around, so we have the requirement to complete the requests sequentially. More formally, request number i must be completed before request number $i + 1$. The lifts are small and must be empty or carrying exactly one passenger at any given time. Also, every request can be completed by any of the lifts.

We want to build a smart system, so we want to minimize the total number of floors when lifts are travelling empty. More precisely, if a lift travels from floor $p$ to floor $q$ without a passenger, then we consider that it has travelled $|p − q|$ floors empty. We should note that the lifts can wait at the same floor for any amount of time, without incurring any additional cost.

Unfortunately, the hotel is old and the machines only have 64 MB of memory! However, we know you’re a great programmer, so this should be no issue for you.

Write a program lifts that, computes the optimal schedule that minimizes the total number of floors that the lifts are travelling empty.

입력

The first line of the standard input contains the numbers $n$ and $k$. The next $n$ lines contain 2ドル$ numbers each - $(l, r)$ for the respective request.

출력

On the single line of the standard output, print the minimum sum of floors where the lifts travel empty.

제한

  • 1ドル ≤ n ≤ 10,000円$
  • 1ドル ≤ k ≤ \min{(30, n)}$
  • 1ドル ≤ l, r ≤ 10^9$

서브태스크

번호배점제한
15

$n \le 22$

220

$n \le 250$

310

$n \le 600$

415

$n \le 1250$

520

$n \le 2500$

630

예제 입력 1

3 2
5 20
8 100
2 80

예제 출력 1

12

힌트

Lift 1ドル$ is initially on floor 5ドル$ and lift 2ドル$ is on floor 8ドル$.

Lift 1ドル$ travels 0ドル$ floors empty and carries the passenger to the 20ドル$th floor.

Lift 1ドル$ travels 12ドル$ floors empty and carries the passenger to the 100ドル$th floor.

Lift 2ドル$ travels 0ドル$ floors empty and carries the passenger to the 80ドル$th floor.

The total number of floors where the lifts travel empty is 0ドル + 12 + 0 = 12$.

출처

Olympiad > International Autumn Tournament in Informatics > 2022 > Group A (Seniors) 6번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /