diff --git "a/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" "b/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" new file mode 100644 index 00000000..a2675f92 --- /dev/null +++ "b/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" @@ -0,0 +1,125 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static int villageCnt, totalSpace, curSpace,ans, deliveryCnt; + static PriorityQueue pq = new PriorityQueue<>(); + static int[] spaces; + static Delivery[] deliveries; + + + static class Delivery implements Comparable{ + int from; + int to; + int boxCnt; + int overlap = 0; + + public Delivery(int from, int to, int boxCnt) { + this.from = from; + this.to = to; + this.boxCnt = boxCnt; + } + + @Override + public int compareTo(Delivery d) { + + return Integer.compare(this.to,d.to); + } + } + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + villageCnt = Integer.parseInt(st.nextToken()); + totalSpace =Integer.parseInt(st.nextToken()); + curSpace = 0; + ans = 0; + + spaces = new int[villageCnt+1]; + deliveryCnt = Integer.parseInt(br.readLine()); + deliveries = new Delivery[deliveryCnt]; + + for (int i = 0; i < deliveryCnt; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int boxCnt = Integer.parseInt(st.nextToken()); + + Delivery d = new Delivery(from,to,boxCnt); + deliveries[i] = d; + + } + + + + } + + public static void process() throws IOException { + getOverlap(); + for (int i = 0; i < deliveryCnt; i++) pq.add(deliveries[i]); + + while(!pq.isEmpty()) { + Delivery d = pq.poll(); + + put(d); + } + + + } + + public static void put(Delivery d) { + + int limit = d.boxCnt; + + for (int i = d.from; i < d.to; i++) { + limit = Math.min(limit, totalSpace - spaces[i]); + } + + for (int i = d.from; i pq = new PriorityQueue<>(); + static int[] spaces; + static Delivery[] deliveries; + + + static class Delivery implements Comparable{ + int from; + int to; + int boxCnt; + int overlap = 0; + + public Delivery(int from, int to, int boxCnt) { + this.from = from; + this.to = to; + this.boxCnt = boxCnt; + } + + @Override + public int compareTo(Delivery d) { + + return Integer.compare(this.to,d.to); + } + } + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + villageCnt = Integer.parseInt(st.nextToken()); + totalSpace =Integer.parseInt(st.nextToken()); + curSpace = 0; + ans = 0; + + spaces = new int[villageCnt+1]; + deliveryCnt = Integer.parseInt(br.readLine()); + deliveries = new Delivery[deliveryCnt]; + + for (int i = 0; i < deliveryCnt; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int boxCnt = Integer.parseInt(st.nextToken()); + + Delivery d = new Delivery(from,to,boxCnt); + deliveries[i] = d; + + } + + + + } + + public static void process() throws IOException { + getOverlap(); + for (int i = 0; i < deliveryCnt; i++) pq.add(deliveries[i]); + + while(!pq.isEmpty()) { + Delivery d = pq.poll(); + + put(d); + } + + + } + + public static void put(Delivery d) { + + int limit = d.boxCnt; + + for (int i = d.from; i < d.to; i++) { + limit = Math.min(limit, totalSpace - spaces[i]); + } + + for (int i = d.from; i