From 2725d1a244dc63b5963441f34772f2f27920723b Mon Sep 17 00:00:00 2001 From: SSUM <116950962+ssum21@users.noreply.github.com> Date: Sat, 6 Sep 2025 22:57:19 +0900 Subject: [PATCH] =?UTF-8?q?[Silver=20III]=20Title:=20=EB=91=90=20=EC=88=98?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9,=20Time:=2088=20ms,=20Memory:=2042660=20K?= =?UTF-8?q?B=20-BaekjoonHub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 백준/Silver/3273. 두 수의 합/README.md | 28 ++++++++++++++++++++++ 백준/Silver/3273. 두 수의 합/두 수의 합.py | 26 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 백준/Silver/3273. 두 수의 합/README.md create mode 100644 백준/Silver/3273. 두 수의 합/두 수의 합.py diff --git a/백준/Silver/3273. 두 수의 합/README.md b/백준/Silver/3273. 두 수의 합/README.md new file mode 100644 index 0000000..49bedec --- /dev/null +++ b/백준/Silver/3273. 두 수의 합/README.md @@ -0,0 +1,28 @@ +# [Silver III] 두 수의 합 - 3273 + +[문제 링크](https://www.acmicpc.net/problem/3273) + +### 성능 요약 + +메모리: 42660 KB, 시간: 88 ms + +### 분류 + +정렬, 두 포인터 + +### 제출 일자 + +2025년 9월 6일 22:57:09 + +### 문제 설명 + +

n개의 서로 다른 양의 정수 a1, a2, ..., an으로 이루어진 수열이 있다. ai의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, ai + aj = x (1 ≤ i < j ≤ n)을 만족하는 (ai, aj)쌍의 수를 구하는 프로그램을 작성하시오.

+ +### 입력 + +

첫째 줄에 수열의 크기 n이 주어진다. 다음 줄에는 수열에 포함되는 수가 주어진다. 셋째 줄에는 x가 주어진다. (1 ≤ n ≤ 100000, 1 ≤ x ≤ 2000000)

+ +### 출력 + +

문제의 조건을 만족하는 쌍의 개수를 출력한다.

+ diff --git a/백준/Silver/3273. 두 수의 합/두 수의 합.py b/백준/Silver/3273. 두 수의 합/두 수의 합.py new file mode 100644 index 0000000..97e7db8 --- /dev/null +++ b/백준/Silver/3273. 두 수의 합/두 수의 합.py @@ -0,0 +1,26 @@ +import sys + +input = sys.stdin.readline + +n = int(input()) +arr = list(map(int, input().split())) +x = int(input()) + +arr.sort() + +left_index = 0 +right_index = n-1 +total = 0 + +while left_index < right_index: + sum_tmp = arr[left_index] + arr[right_index] + if sum_tmp == x: + total += 1 + left_index += 1 + right_index -= 1 + elif sum_tmp > x: + right_index -= 1 + else: + left_index += 1 + +print(total)