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

#GD0000066. Phân lớp học (Classrooms)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân lớp học (Classrooms)

Classrooms

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn activities, each occupying time from sis_i to fif_i, and kk classrooms. Each room hosts at most one activity at a time. Even activities that meet at an endpoint cannot share a room. Each activity may be scheduled once. Maximize the number of activities assigned to rooms.

Input

The first line contains n,kn,k. The next nn lines have si,fis_i,f_i.

Output

Print the maximum number of schedulable activities.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤k≤n1\le k\le n; 1≤si≤fi≤1091\le s_i\le f_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≤si≤fi≤1091\le s_i\le f_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≤si≤fi≤1091\le s_i\le f_i\le10^9 for every ii.

Examples

Input

3 1
1 3
3 5
4 6

Output

2

Explanation

There is one classroom. Intervals [1,3][1,3] and [3,5][3,5] conflict at time 33. Choosing [1,3][1,3] and [4,6][4,6] schedules two activities; three cannot fit.