[Silver III] Title: 두 수의 합, Time: 88 ms, Memory: 42660 KB -BaekjoonHub
This commit is contained in:
28
백준/Silver/3273. 두 수의 합/README.md
Normal file
28
백준/Silver/3273. 두 수의 합/README.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# [Silver III] 두 수의 합 - 3273
|
||||||
|
|
||||||
|
[문제 링크](https://www.acmicpc.net/problem/3273)
|
||||||
|
|
||||||
|
### 성능 요약
|
||||||
|
|
||||||
|
메모리: 42660 KB, 시간: 88 ms
|
||||||
|
|
||||||
|
### 분류
|
||||||
|
|
||||||
|
정렬, 두 포인터
|
||||||
|
|
||||||
|
### 제출 일자
|
||||||
|
|
||||||
|
2025년 9월 6일 22:57:09
|
||||||
|
|
||||||
|
### 문제 설명
|
||||||
|
|
||||||
|
<p>n개의 서로 다른 양의 정수 a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub>으로 이루어진 수열이 있다. a<sub>i</sub>의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, a<sub>i</sub> + a<sub>j</sub> = x (1 ≤ i < j ≤ n)을 만족하는 (a<sub>i</sub>, a<sub>j</sub>)쌍의 수를 구하는 프로그램을 작성하시오.</p>
|
||||||
|
|
||||||
|
### 입력
|
||||||
|
|
||||||
|
<p>첫째 줄에 수열의 크기 n이 주어진다. 다음 줄에는 수열에 포함되는 수가 주어진다. 셋째 줄에는 x가 주어진다. (1 ≤ n ≤ 100000, 1 ≤ x ≤ 2000000)</p>
|
||||||
|
|
||||||
|
### 출력
|
||||||
|
|
||||||
|
<p>문제의 조건을 만족하는 쌍의 개수를 출력한다.</p>
|
||||||
|
|
||||||
26
백준/Silver/3273. 두 수의 합/두 수의 합.py
Normal file
26
백준/Silver/3273. 두 수의 합/두 수의 합.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user