Skip to content

[레넌] 8주차 과제 제출 #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions 8주차/16498/16498_JAVA_레넌.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package boj.p16498;

import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());

int countOfA = parseInt(st.nextToken());
int[] cardOfA = new int[countOfA];
int countOfB = parseInt(st.nextToken());
int[] cardOfB = new int[countOfB];
int countOfC = parseInt(st.nextToken());
int[] cardOfC = new int[countOfC];

st = new StringTokenizer(br.readLine());
for (int i = 0; i < countOfA; i++) {
cardOfA[i] = parseInt(st.nextToken());
}

st = new StringTokenizer(br.readLine());
for (int i = 0; i < countOfB; i++) {
cardOfB[i] = parseInt(st.nextToken());
}

st = new StringTokenizer(br.readLine());
for (int i = 0; i < countOfC; i++) {
cardOfC[i] = parseInt(st.nextToken());
}

Arrays.sort(cardOfA);
Arrays.sort(cardOfB);
Arrays.sort(cardOfC);

int pointA = 0;
int pointB = 0;
int pointC = 0;

int result = Integer.MAX_VALUE;
while (true) {
int max = Math.max(Math.max(cardOfA[pointA], cardOfB[pointB]), cardOfC[pointC]);
int min = Math.min(Math.min(cardOfA[pointA], cardOfB[pointB]), cardOfC[pointC]);
if (max - min < result) {
result = max - min;
}
if (min == cardOfA[pointA] && pointA < cardOfA.length - 1) {
pointA++;
} else if (min == cardOfB[pointB] && pointB < cardOfB.length - 1) {
pointB++;
} else if (min == cardOfC[pointC] && pointC < cardOfC.length - 1) {
pointC++;
} else {
break;
}
}

bw.write(result + "");
bw.flush();

bw.close();
br.close();
}
}