๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

03:19

์ž…๋ ฅ๋ฐ›์€ a, b ๋ฐฐ์—ด์„ ์ •๋ ฌํ•œ ํ›„ ์ˆœํšŒํ•˜๋ฉด์„œ a[i] > b[j]์ธ ๊ฒฝ์šฐ answer์— +1์„ ํ•œ๋‹ค. ๋ฐ˜๋Œ€์ธ ๊ฒฝ์šฐ์—๋Š” (์ด๋ฏธ ์ •๋ ฌ์„ ํ•œ ์ƒํƒœ์ด๋ฏ€๋กœ) b ๋ฐฐ์—ด์„ ๋” ์ˆœํšŒํ•  ํ•„์š”๊ฐ€ ์—†์–ด break๋กœ ๋น ์ ธ๋‚˜์˜จ๋‹ค.


๋ฌธ์ œ

https://www.acmicpc.net/problem/7795


๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ

Swift

let t = Int(readLine()!)! 
for _ in 0..<t {     
	let n = readLine()!.split(separator: " ").map { Int(String($0))! }
    let a = readLine()!.split(separator: " ").map { Int(String($0))! }.sorted()
    let b = readLine()!.split(separator: " ").map { Int(String($0))! }.sorted()
    var answer = 0
    for i in a {
    	for j in b {
        	if i > j {
            	answer += 1
            } else {
            	break
            }
        }
    }
    print(answer) 
}
๋ฐ˜์‘ํ˜•