Skip to content

Commit

Permalink
CT_360
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-Good committed Jan 14, 2025
1 parent 0f4c329 commit 80891bb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BOJ/Java/src/S3/Boj_25045_비즈마켓.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package S3;

import java.io.*;
import java.util.*;

public class Boj_25045_비즈마켓 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

PriorityQueue<Integer> maxA = new PriorityQueue<>(Collections.reverseOrder()); // A를 최대 힙
PriorityQueue<Integer> minB = new PriorityQueue<>(); // B를 최소 힙

st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
maxA.add(Integer.parseInt(st.nextToken()));
}

st = new StringTokenizer(br.readLine());
for (int i = 0; i < M; i++) {
minB.add(Integer.parseInt(st.nextToken()));
}

long sum = 0;

while (!maxA.isEmpty() && !minB.isEmpty()) {
int a = maxA.poll(); // 가장 큰 만족도 아이템
int b = minB.poll(); // 가장 작은 비용을 지불할 고객

if (a >= b) {
sum += a - b;
}
// else의 경우: 거래 불가능하므로 진행하지 않고 다음 고객을 봄.
}

System.out.println(sum);
}
}

0 comments on commit 80891bb

Please sign in to comment.