Submission #54594861
Source Code Expand
// AtCoder Beginner Contest 358
import Foundation
import Collections
let YES = "Yes"
let NO = "No"
func calc(_ N: Int, _ M: Int, _ A: [Int], _ B: [Int]) -> Int {
var A_sorted = A.sorted(by: <)
let B_sorted = B.sorted(by: <)
var totalCost = 0
var counter = 0
for required in B_sorted {
var found = false
for j in counter..<A_sorted.count {
if A_sorted[j] >= required {
totalCost += A_sorted[j]
counter = j+1
found = true
break
}
}
if !found {
return -1
}
}
return totalCost
}
func main() {
let (N, M) = read2Ints()
let A = readInts()
let B = readInts()
let result = calc(N, M, A, B)
print(result)
}
main()
// MARK: - 入力
// 参考:
// https://github.com/kntkymt/AtCoderBeginnersSelection_Swift
func readInt() -> Int {
return Int(Int64(readLine()!)!)
}
func read2Ints(separator: String.Element = " ") -> (a: Int, b: Int) {
let ints = readLine()!.split(separator: separator).map { Int(String($0))! }
return (a: ints[0], b: ints[1])
}
func read3Ints(separator: String.Element = " ") -> (a: Int, b: Int, c: Int) {
let ints = readLine()!.split(separator: separator).map { Int(String($0))! }
return (a: ints[0], b: ints[1], c: ints[2])
}
func read4Ints(separator: String.Element = " ") -> (a: Int, b: Int, c: Int, d: Int) {
let ints = readLine()!.split(separator: separator).map { Int(String($0))! }
return (a: ints[0], b: ints[1], c: ints[2], d: ints[3])
}
func readInts(separator: String.Element = " ") -> [Int] {
return readLine()!.split(separator: separator).map { Int(String($0))! }
}
func readIntsFromNoSpace() -> [Int] {
return readLine()!.map { Int(String($0))! }
}
func readString() -> String {
return readLine()!
}
func read2Strings(separator: String.Element = " ") -> (a: String, b: String) {
let strings = readLine()!.split(separator: separator).map { String($0) }
return (a: strings[0], b: strings[1])
}
func read3Strings(separator: String.Element = " ") -> (a: String, b: String, c: String) {
let strings = readLine()!.split(separator: separator).map { String($0) }
return (a: strings[0], b: strings[1], c: strings[2])
}
func read4Strings(separator: String.Element = " ") -> (a: String, b: String, c: String, d: String) {
let strings = readLine()!.split(separator: separator).map { String($0) }
return (a: strings[0], b: strings[1], c: strings[2], d: strings[3])
}
func readStrings(separator: String.Element = " ") -> [String] {
return readLine()!.split(separator: separator).map { String($0) }
}
func readStringsFromNoSpace() -> [String] {
return readLine()!.map { String($0) }
}
Submission Info
Submission Time
2024-06-15 21:56:34+0900
Task
D - Souvenirs
User
akidon0000
Language
Swift (swift 5.8.1)
Score
350
Code Size
2879 Byte
Status
AC
Exec Time
199 ms
Memory
31896 KiB
Compile Error
[0/1] Planning build
Building for production...
[0/2] Compiling _NumericsShims _NumericsShims.c
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[2/3] Compiling RealModule AlgebraicField.swift
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[4/5] Compiling OrderedCollections _HashTable+Bucket.swift
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[6/7] Compiling DequeModule Compatibility.swift
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[8/9] Compiling Algorithms AdjacentPairs.swift
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[10/11] Compiling Collections Collections.swift
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
[12/13] Compiling Main main.swift
/judge/Sources/main.swift:10:9: warning: variable 'A_sorted' was never mutated; consider changing to 'let' constant
var A_sorted = A.sorted(by: <)
~~~ ^
let
[13/14] Linking Main
Build complete! (9.22s)
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
350 / 350
Status
Set Name
Test Cases
Sample
sample00.txt, sample01.txt, sample02.txt
All
sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt
Case Name
Status
Exec Time
Memory
sample00.txt
AC
4 ms
14764 KiB
sample01.txt
AC
4 ms
14680 KiB
sample02.txt
AC
4 ms
14744 KiB
testcase00.txt
AC
122 ms
25932 KiB
testcase01.txt
AC
161 ms
31168 KiB
testcase02.txt
AC
98 ms
25800 KiB
testcase03.txt
AC
163 ms
31428 KiB
testcase04.txt
AC
147 ms
29960 KiB
testcase05.txt
AC
153 ms
31828 KiB
testcase06.txt
AC
145 ms
25976 KiB
testcase07.txt
AC
26 ms
15892 KiB
testcase08.txt
AC
132 ms
25968 KiB
testcase09.txt
AC
20 ms
16064 KiB
testcase10.txt
AC
184 ms
30368 KiB
testcase11.txt
AC
5 ms
15092 KiB
testcase12.txt
AC
107 ms
25864 KiB
testcase13.txt
AC
82 ms
25396 KiB
testcase14.txt
AC
197 ms
31760 KiB
testcase15.txt
AC
32 ms
16236 KiB
testcase16.txt
AC
196 ms
31896 KiB
testcase17.txt
AC
43 ms
17812 KiB
testcase18.txt
AC
159 ms
26004 KiB
testcase19.txt
AC
32 ms
16788 KiB
testcase20.txt
AC
114 ms
25916 KiB
testcase21.txt
AC
60 ms
19688 KiB
testcase22.txt
AC
162 ms
26056 KiB
testcase23.txt
AC
41 ms
17416 KiB
testcase24.txt
AC
117 ms
25892 KiB
testcase25.txt
AC
44 ms
17636 KiB
testcase26.txt
AC
199 ms
31768 KiB
testcase27.txt
AC
154 ms
29892 KiB
testcase28.txt
AC
197 ms
31816 KiB
testcase29.txt
AC
180 ms
31640 KiB