diff --git "a/BOJ/[1253] \354\242\213\353\213\244/nkw601/Main.java" "b/BOJ/[1253] \354\242\213\353\213\244/nkw601/Main.java" new file mode 100644 index 0000000..d790200 --- /dev/null +++ "b/BOJ/[1253] \354\242\213\353\213\244/nkw601/Main.java" @@ -0,0 +1,53 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +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)); + + int N = Integer.parseInt(br.readLine()); + int[] numbers = new int[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + numbers[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(numbers); + + int ans = 0; + + for (int i = 0; i < N; i++) { + int target = numbers[i]; + int left = 0; + int right = N - 1; + + while (left < right) { + if (left == i) { + left++; + continue; + } + if (right == i) { + right--; + continue; + } + + int sum = numbers[left] + numbers[right]; + + if (sum == target) { + ans++; + break; + } else if (sum < target) { + left++; + } else { + right--; + } + } + } + + System.out.println(ans); + } +} \ No newline at end of file diff --git "a/BOJ/[1446] \354\247\200\353\246\204\352\270\270/nkw601/Main.java" "b/BOJ/[1446] \354\247\200\353\246\204\352\270\270/nkw601/Main.java" new file mode 100644 index 0000000..ce7e50e --- /dev/null +++ "b/BOJ/[1446] \354\247\200\353\246\204\352\270\270/nkw601/Main.java" @@ -0,0 +1,80 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static int N, D; + private static int[] dist; + private static ArrayList[] arrList; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 지름길 개수 + D = Integer.parseInt(st.nextToken()); // 도착 거리 + + dist = new int[D + 1]; + arrList = new ArrayList[D + 1]; + + for (int i = 0; i <= D; i++) { + arrList[i] = new ArrayList<>(); + } + + Arrays.fill(dist, Integer.MAX_VALUE); + + // 원래 도로 추가 + for (int i = 0; i < D; i++) { + arrList[i].add(new int[] { i + 1, 1 }); + } + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + + // 볼 가치 확인 + if (to > D) + continue; + if (cost >= to - from) + continue; + + arrList[from].add(new int[] { to, cost }); + } + + dijkstra(arrList, dist); + + System.out.println(dist[D]); + } + + private static void dijkstra(ArrayList[] adjList, int[] dist) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[1], o2[1])); + + dist[0] = 0; + pq.offer(new int[] { 0, 0 }); + + while (!pq.isEmpty()) { + int[] cur = pq.poll(); + int curV = cur[0]; + int curD = cur[1]; + + if (curD > dist[curV]) + continue; + + for (int[] edge : adjList[curV]) { + int next = edge[0]; + int nextDist = curD + edge[1]; + + if (nextDist < dist[next]) { + dist[next] = nextDist; + pq.offer(new int[] { next, nextDist }); + } + } + } + } +} \ No newline at end of file diff --git "a/BOJ/[20922] \352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264/nkw601/Main.java" "b/BOJ/[20922] \352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264/nkw601/Main.java" new file mode 100644 index 0000000..1589cd1 --- /dev/null +++ "b/BOJ/[20922] \352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264/nkw601/Main.java" @@ -0,0 +1,40 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + int[] arr = new int[N]; + // 등장 횟수 + int[] count = new int[100001]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + int left = 0; + int ans = 0; + + for (int right = 0; right < N; right++) { + // right 한 칸 앞 -> 숫자 등장 + count[arr[right]]++; + // K번보다 많이 나오면 + while (count[arr[right]] > K) { + // 최장연속수열 불가능 + count[arr[left]]--; + left++; + } + + // 길이 갱신하기 + ans = Math.max(ans, right - left + 1); + } + + System.out.println(ans); + } +} \ No newline at end of file