From 7ee437017c9b3336f1027dab70e558f930ee535c Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 28 Jun 2025 23:38:59 +0900 Subject: [PATCH] =?UTF-8?q?[20250628]=20BOJ=20/=20P5=20/=20=ED=8D=BC?= =?UTF-8?q?=EC=A6=90=20=EC=9E=90=EB=A5=B4=EA=B8=B0=20/=20=EA=B6=8C?= =?UTF-8?q?=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\236\220\353\245\264\352\270\260.md" | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 "khj20006/202506/28 BOJ P5 \355\215\274\354\246\220 \354\236\220\353\245\264\352\270\260.md" diff --git "a/khj20006/202506/28 BOJ P5 \355\215\274\354\246\220 \354\236\220\353\245\264\352\270\260.md" "b/khj20006/202506/28 BOJ P5 \355\215\274\354\246\220 \354\236\220\353\245\264\352\270\260.md" new file mode 100644 index 00000000..a8502e80 --- /dev/null +++ "b/khj20006/202506/28 BOJ P5 \355\215\274\354\246\220 \354\236\220\353\245\264\352\270\260.md" @@ -0,0 +1,116 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] r; + static int[][] info; + static long[] c; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + r = new int[N]; + c = new long[N]; + info = new int[N][]; + for(int i=0;i b[0]-a[0]); + + long ans = 0; + + for(int[] f:info) { + int h = f[0], i = f[1]; + if(i=0 && vis[i-1]) { + int left = f(i-1), cur = f(i); + c[cur] += c[left]; + r[left] = cur; + } + vis[i] = true; + ans = Math.max(ans, c[f(i)] * h); + } + io.write(ans + "\n"); + + } + +} +```