File tree Expand file tree Collapse file tree
백준/Gold/23295. 스터디 시간 정하기 1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 3584 KB, 시간: 52 ms
7+ 메모리: 81084 KB, 시간: 376 ms
88
99### 분류
1010
1111누적 합, 스위핑, 슬라이딩 윈도우, 차분 배열 트릭
1212
1313### 제출 일자
1414
15- 2025년 5월 9일 20:52:19
15+ 2025년 5월 9일 21:09:37
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ let MAX = 100005
4+ var checkPoint = [ Int64] ( repeating: 0 , count: MAX)
5+ var psum = [ Int64] ( repeating: 0 , count: MAX)
6+
7+ // 입력 예시
8+ let nt = readLine ( ) !. split ( separator: " " ) . map { Int ( $0) ! } ,
9+ n = nt [ 0 ] ,
10+ t = nt [ 1 ]
11+
12+ for _ in 0 ..< n {
13+ let k = Int ( readLine ( ) !) !
14+ for _ in 0 ..< k {
15+ let line = readLine ( ) !. split ( separator: " " ) . map { Int ( $0) ! }
16+ let s = line [ 0 ]
17+ let e = line [ 1 ]
18+ checkPoint [ s] += 1
19+ checkPoint [ e] -= 1
20+ }
21+ }
22+
23+ // 누적합 계산
24+ psum [ 0 ] = checkPoint [ 0 ]
25+ for i in 1 ..< MAX {
26+ psum [ i] = psum [ i - 1 ] + checkPoint[ i]
27+ }
28+
29+ // 슬라이딩 윈도우
30+ var maxSum : Int64 = 0
31+ var thisSum : Int64 = 0
32+ var left = 0
33+ var right = t - 1
34+ var resultLeft = 0
35+ var resultRight = t
36+
37+ for i in 0 ..< t {
38+ thisSum += psum [ i]
39+ }
40+ maxSum = thisSum
41+
42+ while right < MAX - 1 {
43+ thisSum -= psum [ left]
44+ left += 1
45+ right += 1
46+ thisSum += psum [ right]
47+
48+ if thisSum > maxSum {
49+ maxSum = thisSum
50+ resultLeft = left
51+ resultRight = right + 1
52+ }
53+ }
54+
55+ print ( " \( resultLeft) \( resultRight) " )
You can’t perform that action at this time.
0 commit comments