From 80d03fd0fd8fe8e7be8b51146c7e473dbfdf86ee Mon Sep 17 00:00:00 2001 From: SSUM <116950962+ssum21@users.noreply.github.com> Date: Sun, 14 Sep 2025 22:50:30 +0900 Subject: [PATCH] =?UTF-8?q?[Gold=20IV]=20Title:=20=EB=B6=80=EB=B6=84?= =?UTF-8?q?=ED=95=A9,=20Time:=20380=20ms,=20Memory:=2042244=20KB=20-Baekjo?= =?UTF-8?q?onHub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 백준/Gold/1806. 부분합/README.md | 28 ++++++++++++++++++++++++++++ 백준/Gold/1806. 부분합/부분합.py | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 백준/Gold/1806. 부분합/README.md create mode 100644 백준/Gold/1806. 부분합/부분합.py diff --git a/백준/Gold/1806. 부분합/README.md b/백준/Gold/1806. 부분합/README.md new file mode 100644 index 0000000..66f89ad --- /dev/null +++ b/백준/Gold/1806. 부분합/README.md @@ -0,0 +1,28 @@ +# [Gold IV] 부분합 - 1806 + +[문제 링크](https://www.acmicpc.net/problem/1806) + +### 성능 요약 + +메모리: 42244 KB, 시간: 380 ms + +### 분류 + +누적 합, 두 포인터 + +### 제출 일자 + +2025년 9월 14일 22:49:17 + +### 문제 설명 + +
10,000 이하의 자연수로 이루어진 길이 N짜리 수열이 주어진다. 이 수열에서 연속된 수들의 부분합 중에 그 합이 S 이상이 되는 것 중, 가장 짧은 것의 길이를 구하는 프로그램을 작성하시오.
+ +### 입력 + +첫째 줄에 N (10 ≤ N < 100,000)과 S (0 < S ≤ 100,000,000)가 주어진다. 둘째 줄에는 수열이 주어진다. 수열의 각 원소는 공백으로 구분되어져 있으며, 10,000이하의 자연수이다.
+ +### 출력 + +첫째 줄에 구하고자 하는 최소의 길이를 출력한다. 만일 그러한 합을 만드는 것이 불가능하다면 0을 출력하면 된다.
+ diff --git a/백준/Gold/1806. 부분합/부분합.py b/백준/Gold/1806. 부분합/부분합.py new file mode 100644 index 0000000..90e6425 --- /dev/null +++ b/백준/Gold/1806. 부분합/부분합.py @@ -0,0 +1,27 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +n, s = map(int, input().split()) +arr = deque(map(int, input().split())) + +start, end = 0, 0 +tot = 0 +min_length = sys.maxsize + +while True: + if tot >= s: + min_length=(min(min_length, end - start)) + tot -= arr[start] + start += 1 + elif end == n: + break + else: + tot += arr[end] + end += 1 + +if(min_length == sys.maxsize): + print(0) +else: + print(min_length) \ No newline at end of file