1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import java.util.*;
public class Main2 { static int N = 100010; static int arr[] = new int[N]; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int s = 0; int n = scanner.nextInt(); int h = scanner.nextInt(); int max = 0; int l,r; for (int i = 0;i<n;i++){ l = scanner.nextInt(); r = scanner.nextInt(); arr[l]++; arr[r++]--; max = Math.max(max,r); } int res = 0; for (int i = 1;i<=max;i++){ arr[i] = arr[i]+arr[i-1]; if (arr[i]>=h) res++; } System.out.println(res); } }
|