최대 1 분 소요



https://www.acmicpc.net/problem/3273



🔍 문제 풀이

문제 도식화

정렬할 생각을 왜 못했을까..

assets/images/2025/3273.jpg



💻 코드

전체 코드

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

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[] arr = new int[n];

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

        int k = Integer.parseInt(br.readLine());

        Arrays.sort(arr);

        int cnt = 0, s = 0, e = n-1;
        while(s<e){
            if(arr[s] + arr[e] > k) e--;
            else{
                if(arr[s] + arr[e] == k) cnt++;
                s++;
            }
        }

        System.out.println(cnt);
    }
}


카테고리:

업데이트:

댓글남기기