import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables,lists,random template get():string = stdin.readLine() template times(n:int,body:untyped): untyped = (for _ in 0.. 0: # 末尾から木を整形 let parent = (i - 1) div 2 if h.compare(h.nodes[parent],node) <= 0: break h.nodes[i] = h.nodes[parent] i = parent h.nodes[i] = node proc pop*[T](h:var Heap[T]):T = result = h.nodes[0] # rootと末尾を入れ替えて木を整形 let x = h.nodes[^1] h.nodes.setLen(h.nodes.len() - 1) let size = h.nodes.len() var i = 0 while true : let L = i * 2 + 1 let R = i * 2 + 2 if L >= size : break let child = if R < size and h.compareNode(R,L) <= 0 : R else: L if h.compare(x,h.nodes[child]) <= 0: break h.nodes[i ] = h.nodes[child] i = child h.nodes[i] = x let N = get().parseInt # ~1500 A = get().split().map(parseInt) # my lv B = get().split().map(parseInt) #enemy lv # 一番レベルの低い 一番戦ってないものを戦わせる type monster = tuple[lv:int,cnt:int] var myInitialHeap = newHeap( proc (a,b:monster):int = if a.lv == b.lv : a.cnt - b.cnt else: a.lv - b.lv ) for a in A: myInitialHeap.push((a,0)) var res = 1e12.int for i in 0.. mx : mx = me.cnt if res <= mx: break res .min= mx echo res #[ type # 左から大きい順にソート CPriorityQueue {.importcpp: "std::priority_queue", header: "".} [T] = object CPair {.importcpp: "std::pair", header: "".} [T1,T2] = object proc cNewPriorityQueue(T: typedesc): CPriorityQueue[T] {.importcpp: "std::priority_queue<'*1>()", nodecl.} proc cMakePair[T1,T2](t1:T1,t2:T2):CPair[T1,T2] {.importcpp: "std::make_pair(@)", nodecl.} proc first[T1,T2](this: CPair[T1,T2]): T1 {.importcpp: "#.first", nodecl.} proc second[T1,T2](this: CPair[T1,T2]): T2 {.importcpp: "#.second", nodecl.} proc cpop[T](this: CPriorityQueue[T]) {.importcpp: "#.pop(@)", nodecl.} proc newPriorityQueue*[T](): CPriorityQueue[T] = cNewPriorityQueue(T) proc empty*[T](this:CPriorityQueue[T]):bool {.importcpp: "#.empty(@)", nodecl.} proc size*[T](this:CPriorityQueue[T]):int {.importcpp: "#.size(@)", nodecl.} proc ctop*[T](this: CPriorityQueue[T]):T {.importcpp: "#.top(@)", nodecl.} proc top*[T](this: CPriorityQueue[T]):T {.importcpp: "#.top(@)", nodecl.} proc push*[T](this: CPriorityQueue[T],x:T) {.importcpp: "#.push(@)", nodecl.} proc pop*[T](this:var CPriorityQueue[T]):T =(result = this.top();this.cpop()) proc newPriorityQueue*[T1,T2](): CPriorityQueue[CPair[T1,T2]] = cNewPriorityQueue(CPair[T1,T2]) proc push*[T1,T2](this:var CPriorityQueue[CPair[T1,T2]],x:(T1,T2)): void = this.push(cMakePair(x[0],x[1])) proc pop*[T1,T2](this:var CPriorityQueue[CPair[T1,T2]]):(T1,T2) = let res = this.top();this.cpop();return (res.first,res.second) proc top*[T1,T2](this:var CPriorityQueue[CPair[T1,T2]]):(T1,T2) = let res = this.ctop();return (res.first,res.second) let N = get().parseInt # ~1500 A = get().split().map(parseInt) # my lv B = get().split().map(parseInt) #enemy lv # 一番レベルの低い 一番戦ってないものを戦わせる type monster = tuple[lv:int,cnt:int] var myInitialHeap = newPriorityQueue[int,int]() for a in A: myInitialHeap.push((-a,0)) var res = 1e10.int for i in 0.. mx : mx = me[1] * -1 if res <= mx: break res .min= mx echo res ]#