diff --git "a/khj20006/202503/06 BOJ P5 \353\254\264\354\204\234\354\232\264 \354\225\204\353\245\264\353\260\224\354\235\264\355\212\270.md" "b/khj20006/202503/06 BOJ P5 \353\254\264\354\204\234\354\232\264 \354\225\204\353\245\264\353\260\224\354\235\264\355\212\270.md" new file mode 100644 index 00000000..7431e0f3 --- /dev/null +++ "b/khj20006/202503/06 BOJ P5 \353\254\264\354\204\234\354\232\264 \354\225\204\353\245\264\353\260\224\354\235\264\355\212\270.md" @@ -0,0 +1,83 @@ +```java + +import java.util.*; +import java.io.*; + + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N; + static int[] r, A; + static long[] C; + static boolean[] V; + static int[][] info; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = Integer.parseInt(br.readLine()); + A = new int[N]; + r = new int[N]; + C = new long[N]; + V = new boolean[N]; + info = new int[N][2]; + nextLine(); + for(int i=0;i b[0]-a[0]); + + } + + static void solve() throws Exception{ + + long ans = 0; + for(int[] n:info) { + int val = n[0], idx = n[1]; + V[idx] = true; + if(idx > 0 && V[idx-1]) { + int x = f(idx-1), y = f(idx); + C[y] += C[x]; + r[x] = y; + } + + if(idx < N-1 && V[idx+1]) { + int x = f(idx+1), y = f(idx); + C[y] += C[x]; + r[x] = y; + } + + ans = Math.max(ans, C[f(idx)] * val); + } + bw.write(ans + "\n"); + } + +} + +```