diff --git "a/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\353\221\220_\354\232\251\354\225\241.java" "b/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\353\221\220_\354\232\251\354\225\241.java" new file mode 100644 index 0000000..33970cf --- /dev/null +++ "b/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\353\221\220_\354\232\251\354\225\241.java" @@ -0,0 +1,80 @@ +package week34.강성욱.baekjoon; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.StringTokenizer; + +/** + * PackageName : week34.강성욱.baekjoon + * FileName : 두_용액 + * Author : Baekgwa + * Date : 25. 12. 22. + * Description : + * ===================================================================================================================== + * DATE AUTHOR NOTE + * --------------------------------------------------------------------------------------------------------------------- + * 25. 12. 22. Baekgwa Initial creation + */ +public class 두_용액 { + public class Main { + // 어짜피 두개만 선택함. + // -2, 4, -99, -1, 98 + // 정렬해둘까? + // -99, -2, -1, 4, 98 + // 다 확인하면? 100,000^2 = 10,000,000,000 = 백억은 좀; + // 투포인터? + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); //용액 종류 + int[] map = new int[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int i=0; i result = new ArrayList<>(); + + while(left < right) { + int leftVal = map[left]; + int rightVal = map[right]; + + int sum = leftVal + rightVal; + + // 현재값이 가장 작은 값인지 확인해보기 + // 0에 가까운걸 찾기 때문에, 절대값으로 변환해서 사용 + if(nowMin > Math.abs(sum)) { + nowMin = Math.abs(sum); + result.clear(); + result.add(leftVal); + result.add(rightVal); + } + + // 현재 값에 따라서, 포인터 움직이기 + if(sum == 0) { + // 0 이면 더 이상 탐색할 필요도 없이, 완벽한 혼합용액 + break; + } else if(sum < 0) { + // 음수인 경우에는 left 를 늘려야함 + left++; + } else { + right--; + } + } + + System.out.println(result.get(0) + " " + result.get(1)); + } + } +} diff --git "a/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\354\271\264\353\223\234_\354\240\225\353\240\254\355\225\230\352\270\260.java" "b/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\354\271\264\353\223\234_\354\240\225\353\240\254\355\225\230\352\270\260.java" new file mode 100644 index 0000000..f8af528 --- /dev/null +++ "b/week34/\352\260\225\354\204\261\354\232\261/baekjoon/\354\271\264\353\223\234_\354\240\225\353\240\254\355\225\230\352\270\260.java" @@ -0,0 +1,62 @@ +package week34.강성욱.baekjoon; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.PriorityQueue; + +/** + * PackageName : week34.강성욱.baekjoon + * FileName : 카드_정렬하기 + * Author : Baekgwa + * Date : 25. 12. 22. + * Description : + * ===================================================================================================================== + * DATE AUTHOR NOTE + * --------------------------------------------------------------------------------------------------------------------- + * 25. 12. 22. Baekgwa Initial creation + */ +public class 카드_정렬하기 { + public class Main { + + // 가장 작은거끼리 합해나가는게 더 이득인가? + // 50, 51, 60, 100 + // (50 + 51) + (101 + 60) + (161 + 100) = 523 + // (50 + 51) + (60 + 100) + (101 + 106) = 468 + // 한번만 정렬할게 아니고, 계속 꾸준히 정렬이 필요 + // 뭉치가 하나만 들어올 수가 있어서, 그거 처리필요. + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + PriorityQueue pq = new PriorityQueue<>(); + + int N = Integer.parseInt(br.readLine()); // 카드 묶음 수 + + for(int i=0; i= 2) continue; + distinct++; + } + + // 쿠폰으로 먹는거 중복 확인 + max = distinct; + if(count[c] == 0) { + max++; + } + + // 전체 확인 + while(left < N) { + int now = belt[left]; // 이번에 뺄 스시 + count[now]--; + if(count[now] == 0) { + distinct--; + } + + // 스시 더하기 + right = (left + k) % N; + now = belt[right]; + count[now]++; + if(count[now] == 1) { + distinct++; + } + + int current = distinct; + if(count[c] == 0) { + current++; + } + + max = Math.max(max, current); + + left++; + } + + System.out.println(max); + } + } +}