fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val p = readLine()!!.split(" ").map { it.toLong() }.sorted()
    val f = readLine()!!.split(" ").map { it.toLong() }.sortedDescending()

    val sum = p.sum()
    if (sum < n) {
        println(0)
        return
    }

    // binary search
    var from = 0L
    var to = 1000000000001L

    while (from < to) {
        val mid = (from + to) / 2
        if (ok(p, f, k, mid)) to = mid
        else from = mid + 1
    }
    println(from)
}

fun ok(p: List<Long>, f: List<Long>, k: Long, target: Long) : Boolean {
    val limit = p.size
    var remain = k
    (0 until limit).forEach {
        var a = p[it]
        var b = f[it]

        if (a * b > target) {
            val m = target / b
            remain -= (a - m)
        }

        if (remain < 0L) return false
    }
    return true
}
