diff --git "a/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" "b/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" new file mode 100644 index 00000000..937bffd7 --- /dev/null +++ "b/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" @@ -0,0 +1,70 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static int[] arr; + static int[][] manipulation; + static int[] correct; + static int ans = -1; + + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + arr = new int[N+1]; + + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + correct = Arrays.copyOf(arr, N+1); + Arrays.sort(correct); + + M = Integer.parseInt(br.readLine()); + manipulation = new int[M][3]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + manipulation[i] = new int[]{a,b,c}; + } + + dijkstra(); + + bw.write(ans+""); + bw.close(); + } + static void dijkstra(){ + PriorityQueue pq = new PriorityQueue<>((a,b) -> a[0]-b[0]); + Map dist = new HashMap<>(); + pq.offer(arr); + dist.put(Arrays.toString(Arrays.copyOfRange(arr,1,N+1)),0); + + while (!pq.isEmpty()){ + int[] cur = pq.poll(); + String curString = Arrays.toString(Arrays.copyOfRange(cur,1,N+1)); + + if(dist.get(curString) < cur[0]) continue; + + for(int i = 0; i