fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class MovieFestival2 {
  5. public static void main(String[] args) throws IOException {
  6. setIO();
  7.  
  8. st = nl();
  9. int N = ni(st), K = ni(st);
  10. Movie[] M = new Movie[N];
  11. for (int i = 0; i < N; i++) {
  12. st = nl();
  13. int s = ni(st), e = ni(st);
  14. M[i] = new Movie(s, e);
  15. }
  16. Arrays.sort(M);
  17.  
  18. ms.put(0, K);
  19.  
  20. int ans = 0;
  21. for (int i = 0; i < N; i++) {
  22. if (ms.floorKey(M[i].s) != null) {
  23. delete(ms.floorKey(M[i].s));
  24. add(M[i].e);
  25.  
  26. ans++;
  27. }
  28. }
  29.  
  30. out.println(ans);
  31.  
  32. f.close();
  33. out.close();
  34. }
  35.  
  36. static TreeMap<Integer, Integer> ms = new TreeMap<>();
  37.  
  38. static void add(int x) {
  39. ms.put(x, ms.getOrDefault(x, 0) + 1);
  40. }
  41.  
  42. static void delete(int x) {
  43. int c = ms.get(x);
  44. ms.put(x, --c);
  45. if (c == 0)
  46. ms.remove(x);
  47. }
  48.  
  49. static class Movie implements Comparable<Movie> {
  50. int s, e;
  51. Movie(int s, int e) {
  52. this.s = s;
  53. this.e = e;
  54. }
  55.  
  56. public int compareTo(Movie o) {
  57. return Integer.compare(this.e, o.e);
  58. }
  59. }
  60.  
  61. static BufferedReader f;
  62. static PrintWriter out;
  63. static StringTokenizer st;
  64.  
  65. static int ni(StringTokenizer st) {
  66. return Integer.parseInt(st.nextToken());
  67. }
  68.  
  69. static int ni() throws IOException {
  70. return Integer.parseInt(f.readLine());
  71. }
  72.  
  73. static StringTokenizer nl() throws IOException {
  74. return new StringTokenizer(f.readLine());
  75. }
  76.  
  77. static int[] nia(int N) throws IOException {
  78. StringTokenizer st = nl();
  79. int[] A = new int[N];
  80. for (int i = 0; i < N; i++)
  81. A[i] = ni(st);
  82. return A;
  83. }
  84.  
  85. static void setIn(String s) throws IOException {
  86. f = new BufferedReader(new FileReader(s));
  87. }
  88.  
  89. static void setOut(String s) throws IOException {
  90. out = new PrintWriter(new FileWriter(s));
  91. }
  92.  
  93. static void setIn() {
  94. }
  95.  
  96. static void setOut() {
  97. }
  98.  
  99. static void setIO(String s) throws IOException {
  100. setIn(s + ".in");
  101. setOut(s + ".out");
  102. }
  103.  
  104. static void setIO() {
  105. setIn();
  106. setOut();
  107. }
  108. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: class MovieFestival2 is public, should be declared in a file named MovieFestival2.java
public class MovieFestival2 {
       ^
1 error
stdout
Standard output is empty