File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+ import java.util.*;
4+
5+ public class Main {
6+ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+ private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+ private static List<int[]> events;
9+ private static int N;
10+ public static void main(String[] args) throws IOException {
11+ init();
12+
13+ int answer = sweeping();
14+
15+ bw.write(answer + "\n");
16+ bw.flush();
17+ bw.close();
18+ br.close();
19+ }
20+
21+ private static void init() throws IOException {
22+ N = Integer.parseInt(br.readLine());
23+ events = new ArrayList<>();
24+
25+ for (int i = 0; i < N; i++) {
26+ StringTokenizer st = new StringTokenizer(br.readLine());
27+ events.add(new int[]{Integer.parseInt(st.nextToken()), 0});
28+ events.add(new int[]{Integer.parseInt(st.nextToken()), 1});
29+ }
30+
31+ events.sort((o1, o2) -> {
32+ if (o1[0] == o2[0]) return Integer.compare(o2[1], o1[1]);
33+ return Integer.compare(o1[0], o2[0]);
34+ });
35+ }
36+
37+ private static int sweeping() {
38+ int result = 0;
39+ int count = 0;
40+
41+ for (int[] event : events) {
42+ if (event[1] == 0) count++;
43+ else count--;
44+
45+ result = Math.max(result, count);
46+ }
47+
48+ return result;
49+ }
50+ }
51+ ```
You can’t perform that action at this time.
0 commit comments