RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00704

Dodatna

설명

The famous mentor Jakov loves teaching and helping diligent students. This school
year he decided to help some truly unusual students and teach additional computer
science classes. Namely, each of the \(n\) students has very strange requirements that
must be satisfied for them to even show up to the extra class, but more on that
another time.
Jakov’s conditions for holding the extra class are much simpler and are as follows:
• All students who will attend the extra class must be in the school from
the beginning to the end of the extra class.
• There must be at least \(k\) students in the extra class, otherwise it will not be
held at all.
With the help of the principal, Jakov discovered the schedules of all \(n\) students, and for each student
\(i\) (\(1 \le i \le n\)) he knows that they are in the school between the \(l_{i}-th\) and \(r_{i}-th\) millisecond of the day
(exclusively).
Help Jakov by answering the question: what is the maximum possible duration of the extra class he can
hold? If Jakov cannot hold an extra class at all, output the number 0.
The first millisecond during which student \(i\) is in the school is \(l_{i}\), and the last is \(r_{i} - 1\).

제약
입력 형식

The first line contains the natural numbers \(n\) and \(k\) (\(1 \le n\), \(k \le 3 \cdot 10^{5}\)) from the problem statement.
Each of the following \(n\) lines contains 2 numbers \(l_{i}\) and \(r_{i}\) (\(1 \le l_{i} < r_{i} \le 86\,400\,000\)), from the problem
statement.

출력 형식

In the first and only line, output a single number — the maximum duration of the extra class that Jakov
can organize, or 0 if it is impossible.

서브태스크
서브태스크점수설명

1

13점

\(K = 1\)

2

27점

\(1 \le N \le 1000\), \(K = 2\)

3

11점

\(r_{i} \le 100\)

4

19점

No additional constraints.

예제 1
입력
5 1
1 3
1 4
1 5
1 6
1 7
출력
6
예제 2
입력
5 2
6 10
8 14
5 9
5 6
4 6
출력
3
설명

Clarification of the second example: The longest duration of the extra class that Jakov can organize
is 3 seconds because the 1st and 3rd student will attend it in the 6th, 7th, and 8th second.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 2

평가 및 의견

Dodatna

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Dodatna

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8