Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

The Maximum Number of Customers

$N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours.

Constraints

$ 1 \leq N \leq 10^5 $

$ 1 \leq T \leq 10^5 $

$ 0 \leq l_i < r_i \leq T $

Input

The input is given in the following format.

$N$ $T$

$l_1$ $r_1$

$l_2$ $r_2$

:

$l_N$ $r_N$

Output

Print the maximum number of persons in a line.

Sample Input 1

6 10
0 2
1 3
2 6
3 8
4 10
5 10

Sample Output 1

4

Sample Input 2

2 2
0 1
1 2

Sample Output 2

1

Solution in C (judge verdict: Accepted)

#include <stdio.h>

int times[100001];

void add(int start, int end, int num) {
  int i;

  for (i = start; i < end; i++)
    times[i] += num;
}

int main() {
  int n, T, arrive, leave, i, out = 0;

  scanf("%d %d", &n, &T);
  scanf("%d %d", &arrive, &leave);

  if (50000 > leave - arrive) {
    memset(times, 0, sizeof(times));
    add(arrive, leave, 1);

    for (i = 1; i < n; i++) {
      scanf("%d %d", &arrive, &leave);
      add(arrive, leave, 1);
    }
  } else {
    /*    for (i = 0; i < T; i++)
      times[i] = n;
    
    add(0, arrive, -1);
    add(out, T, -1);

    for (i = 1; i < n; i++) {
      scanf("%d %d", &arrive, &leave);
      add(0, arrive, -1);
      add(leave, T, -1);
    }
    */

    for (i = 0; i < T; i++)
      times[i] = n;

    add(0, arrive, -1);
    add(leave, T, -1);
    
    for (i = 1; i < n; i++) {
      scanf("%d%d", &arrive, &leave);
      add(0, arrive, -1);
      add(leave, T, -1);
    }
  }
  
  int max = 0;


  for(i=0; i<T; i++){
    max = (max < *(times+i) ? *(times+i) : max);
  }

  out = max;
  /*
  for (i = 0; i < T; i++) {
    if (out < times[i])
      out = times[i];
  }
  */

  printf("%d\n", out);
}