Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- swift navigationcontroller
- RxSwift
- swift 점선
- custom navigation bar
- swift 백준
- 버튼 피드백
- claen architecture
- swift custom ui
- button configuration
- task cancel
- SWIFT
- custom ui
- rxdatasources
- swift bottomsheet
- uikit toast
- swift dashed line
- coordinator
- BFS
- traits
- task cancellation
- UIKit
- paragraph style
- Tuist
- reactorkit
- custombottomsheet
- swift concurrency
- identifiable
- 타임라인 포맷팅
- domain data
- DP
Archives
- Today
- Total
김경록의 앱 개발 여정
[Swift 백준] 2559 수열 본문
풀이 아이디어
- 슬라이딩 윈도우 알고리즘을 활용합니다
자세한 풀이 방식은 주석을 참고해주세요.
풀이
let nk = readLine()!.split(separator: " ").map{Int($0)!}
// n: 총 날짜수, k: 연속 날짜 수
let (n,k) = (nk[0],nk[1])
let input = readLine()!.split(separator: " ").map{Int($0)!}
//첫 구간합을 구합니다.
var initialSum = input[0..<k].reduce(0, +)
var maxResult = initialSum
for i in k..<n {
// 윈도우를 움직이며, 가장 왼쪽값(지나간 값)은 빼주고 가장 오른쪽값(새로 들어오는 값)을 더합니다
initialSum = initialSum - input[i - k] + input[i]
maxResult = max(maxResult, initialSum)
}
print(maxResult)
'Algorithm' 카테고리의 다른 글
[Swift 백준] 음식물 피하기 (0) | 2025.01.24 |
---|---|
[Swift 백준] 21921 블로그 (0) | 2025.01.23 |
[Swift 백준] 14465 소가 길을 건너간 이유 5 (0) | 2025.01.21 |
[Swift 백준] 18870 좌표 압축 (0) | 2025.01.20 |
[Swift 백준] 17266 어두운 굴다리 (0) | 2025.01.16 |