Skip to content

Commit db03185

Browse files
committed
[Silver IV] Title: 보물, Time: 8 ms, Memory: 69112 KB -BaekjoonHub
1 parent 6f57f9b commit db03185

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

백준/Silver/1026. 보물/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 79516 KB, 시간: 12 ms
7+
메모리: 69112 KB, 시간: 8 ms
88

99
### 분류
1010

1111
수학, 그리디 알고리즘, 정렬
1212

1313
### 제출 일자
1414

15-
2025년 6월 13일 16:39:20
15+
2025년 8월 28일 11:45:30
1616

1717
### 문제 설명
1818

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
import Foundation
2-
3-
class FileIO {
4-
@inline(__always) private var buffer: [UInt8] = Array(FileHandle.standardInput.readDataToEndOfFile()) + [0], byteIdx = 0
5-
6-
@inline(__always) private func readByte() -> UInt8 {
7-
defer { byteIdx += 1 }
8-
return buffer.withUnsafeBufferPointer { $0[byteIdx] }
9-
}
10-
11-
@inline(__always) func readInt() -> Int {
12-
var number = 0, byte = readByte(), isNegative = false
13-
while byte == 10 || byte == 32 { byte = readByte() }
14-
if byte == 45 { byte = readByte(); isNegative = true }
15-
while 48...57 ~= byte { number = number * 10 + Int(byte - 48); byte = readByte() }
16-
return number * (isNegative ? -1 : 1)
17-
}
1+
let n = Int(readLine()!)!
2+
let a = readLine()!.split { $0 == " " }.map { Int(String($0))! }.sorted { $0 < $1 }
3+
let b = readLine()!.split { $0 == " " }.map { Int(String($0))! }.sorted { $0 > $1 }
4+
var answer = 0
5+
for i in 0..<n {
6+
answer += a[i] * b[i]
187
}
19-
20-
let io = FileIO()
21-
let n = io.readInt()
22-
let aList = (0..<n).map { _ in io.readInt() }.sorted { $0 < $1 }
23-
let bList = (0..<n).map { _ in io.readInt() }.sorted { $0 > $1 }
24-
25-
let answer = zip(aList, bList).map { a, b in a*b }.reduce(0, +)
26-
278
print(answer)

0 commit comments

Comments
 (0)