0
0

More than 1 year has passed since last update.

Posted at

# 正解済み問題

## A - Repression

こちら問題ページ

ソートして後ろ二つを足し算。

``````let abc = readLine()!.split(separator: " ").map{Int(\$0)!}.sorted()
print(abc[1] + abc[2])
``````

## B - Alcoholic

こちら問題ページ

``````let nx = readLine()!.split(separator: " ")
let n: Int = Int(nx[0])!
var x: Int = Int(nx[1])! * 100

var totalMl: Int = 0
var counter = 0
for _ in 1...n {
let vp = readLine()!.split(separator: " ").map{Int(\$0)!}
let ml = vp[0] * vp[1]

totalMl += ml
counter += 1
if x < totalMl {
break
}
}

if x < totalMl {
print(counter)
} else {
print(-1)
}
``````

# 誤答及び、未解答問題

## D - Replacing

こちら問題ページ

``````let n = Int(readLine()!)!
var aArray = readLine()!.split(separator: " ").map{Int(\$0)!}

for _ in 0..<q {
let bc = readLine()!.split(separator: " ").map{Int(\$0)!}
aArray.replace(before: bc[0], after: bc[1])
print(aArray.reduce(0, +))
}

extension Array where Element: Equatable {
mutating func replace(before: Array.Element, after: Array.Element) {
self = self.map { (\$0 == before) ? after : \$0 }
}
}
``````

``````func readInts() -> [Int] {
return readLine()!.split(separator: " ").map{ Int(String(\$0))! }
}

let m = 100000
var s = a.reduce(0, +)
var counter = [Int](repeating: 0, count: m + 1)
a.forEach{ counter[\$0] += 1 }

for _ in 0..<q {
let b = query[0], c = query[1]

let diff = (c - b) * counter[b]
counter[c] += counter[b]
counter[b] = 0

s += diff
print(s)
}
``````

# 参考

0
0
0

Register as a new user and use Qiita more conveniently

1. You get articles that match your needs
2. You can efficiently read back useful information
3. You can use dark theme
What you can do with signing up
0
0