PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000063. Liên hoan phim II (Movie Festival II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Liên hoan phim II (Movie Festival II)

Movie Festival II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn movies with intervals [ai,bi][a_i,b_i] and kk viewers. Each viewer can watch one entire movie at a time, and may start another exactly when the previous ends. Each movie counts at most once. Maximize the total number of fully watched movies.

Input

The first line has n,kn,k. The next nn lines contain ai,bia_i,b_i.

Output

Print the maximum number of movies.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤k≤n1\le k\le n; 1≤ai<bi≤1091\le a_i<b_i\le10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤k≤n1\le k\le n; 1≤ai<bi≤1091\le a_i<b_i\le10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤k≤n1\le k\le n; 1≤ai<bi≤1091\le a_i<b_i\le10^9 for every ii.

Examples

Input

5 2
1 5
8 10
3 6
2 5
6 9

Output

4

Explanation

Two viewers can take [1,5],[6,9][1,5],[6,9] and [2,5],[8,10][2,5],[8,10], respectively: 44 movies. All 55 cannot fit because three movies overlap between time 33 and time 55.