From edc8aaa7998805fcfd97e60e5d4236951d838f62 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Thu, 16 Oct 2025 19:19:14 +0900 Subject: [PATCH] =?UTF-8?q?[20251016]=20BOJ=20/=20G3=20/=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=EB=8C=80=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3 \352\265\254\354\241\260\353\214\200.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "Ukj0ng/202510/16 BOJ G3 \352\265\254\354\241\260\353\214\200.md" diff --git "a/Ukj0ng/202510/16 BOJ G3 \352\265\254\354\241\260\353\214\200.md" "b/Ukj0ng/202510/16 BOJ G3 \352\265\254\354\241\260\353\214\200.md" new file mode 100644 index 00000000..65ef5e92 --- /dev/null +++ "b/Ukj0ng/202510/16 BOJ G3 \352\265\254\354\241\260\353\214\200.md" @@ -0,0 +1,87 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static List events; + private static Map teamCount; + private static int N, M; + public static void main(String[] args) throws IOException { + init(); + int answer = solve(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + events = new ArrayList<>(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int l = Integer.parseInt(st.nextToken()); + int r = Integer.parseInt(st.nextToken()); + int team = Integer.parseInt(st.nextToken()); + + int startS = Math.max(0, l-M); + int endS = r; + + events.add(new int[]{startS, 0, team}); + events.add(new int[]{endS, 1, team}); + } + + Collections.sort(events, (o1, o2) -> Integer.compare(o1[0], o2[0])); + + teamCount = new HashMap<>(); + } + + private static int solve() { + int answer = 0; + int prevS = -1; + int validTeams = 0; + + for (int[] element : events) { + if (element[0] != prevS && prevS >= 0) { + answer = Math.max(answer, validTeams); + } + + int team = element[2]; + int oldCount = teamCount.getOrDefault(team, 0); + + if (element[1] == 0) { + int newCount = oldCount + 1; + teamCount.put(team, newCount); + + if (oldCount == 1 && newCount == 2) { + validTeams++; + } + } else { + int newCount = oldCount - 1; + + if (oldCount == 2 && newCount == 1) { + validTeams--; + } + + if (newCount == 0) { + teamCount.remove(team); + } else { + teamCount.put(team, newCount); + } + } + + prevS = element[0]; + } + + answer = Math.max(answer, validTeams); + return answer; + } +} +```