From 8c1c5ad0893d93d084a144021fe801f6071dd950 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Fri, 12 Sep 2025 11:04:58 +0900 Subject: [PATCH] =?UTF-8?q?[20250912]=20BOJ=20/=20P5=20/=20=ED=9E=88?= =?UTF-8?q?=EC=8A=A4=ED=86=A0=EA=B7=B8=EB=9E=A8=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44\355\206\240\352\267\270\353\236\250.md" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "0224LJH/202509/12 BOJ \355\236\210\354\212\244\355\206\240\352\267\270\353\236\250.md" diff --git "a/0224LJH/202509/12 BOJ \355\236\210\354\212\244\355\206\240\352\267\270\353\236\250.md" "b/0224LJH/202509/12 BOJ \355\236\210\354\212\244\355\206\240\352\267\270\353\236\250.md" new file mode 100644 index 00000000..2b025590 --- /dev/null +++ "b/0224LJH/202509/12 BOJ \355\236\210\354\212\244\355\206\240\352\267\270\353\236\250.md" @@ -0,0 +1,105 @@ +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + + + static int blockCnt; + static long ans; + static int[] blocks; + static PriorityQueue pq = new PriorityQueue<>(); + static HashSet nums = new HashSet<>(); + static PriorityQueue numPq = new PriorityQueue<>(); + + static class Block implements Comparable{ + int start; + int height; + + public Block (int start, int height) { + this.start = start; + this.height = height; + } + + @Override + public int compareTo(Block b) { + return Integer.compare(b.height, this.height); + } + } + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + public static void init() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + blockCnt = Integer.parseInt(br.readLine()); + blocks = new int[blockCnt]; + ans = 0; + for (int i = 0; i < blockCnt; i++) { + blocks[i] = Integer.parseInt(br.readLine()); + nums.add(blocks[i]); + } + + + } + + public static void process() { + ans = findLargest(0,blockCnt-1); + + + } + + public static long findLargest(int start, int end) { + + if (start == end) return blocks[start]; + + int mid = (start+end)/2; + long leftMax = findLargest(start,mid); + long rightMax = findLargest(mid+1,end); + long max = Math.max(leftMax, rightMax); + + int leftIdx = mid; + int rightIdx = mid+1; + long curNum = Math.min(blocks[leftIdx], blocks[rightIdx]); + long curMax =curNum*(rightIdx-leftIdx+1); + + while(true) { + + if (leftIdx == start && rightIdx == end) break; + int nLeftNum = 0; + int nRightNum = 0; + if (start < leftIdx) nLeftNum = blocks[leftIdx-1]; + if (rightIdx < end) nRightNum = blocks[rightIdx+1]; + + if (nLeftNum <= nRightNum && rightIdx != end) { + rightIdx++; + } else { + leftIdx--; + } + + curNum = Math.min(curNum, blocks[rightIdx]); + curNum = Math.min(curNum, blocks[leftIdx]); + curMax = Math.max(curMax, curNum*(rightIdx-leftIdx+1)); + + } + + max = Math.max(max, curMax); + + return max; + } + + + + + public static void print() { + System.out.println(ans); + } +} +```