//package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextLong(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.size < k || c[arr[i].second] > v[0]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


//package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextLong(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    if (k == 0) {
        c.forEach { print("$it ") }
        return
    }
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.size < k || c[arr[i].second] > v[0]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


//package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextInt(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.isEmpty() || c[arr[i].second] > v[v.size - 1]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextInt(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.isEmpty() || c[arr[i].second] > v[v.size - 1]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextLong(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.isEmpty() || c[arr[i].second] > v[0]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val p = Array<Pair<Int, Int>>(n) { Pair(scanner.nextInt(), it) }.sortedBy { it.first }
    val c = IntArray(n) { scanner.nextInt() }
    val Q = IntArray(k + 1) { -1 }
    val res = IntArray(n)
    p.forEach {
        Q[0] = c[it.second]
        for (i in 0..k)
            if (Q[i] != -1)
                res[it.second] += Q[i];
        Q.sort()
    }
    res.forEach { print("$it ") }

}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}
//class Pair(var a: Int, var b: Int): Comparable<Pair> {
//    override fun compareTo(other: Pair): Int {
//        return b - a - other.b + other.a
//    }
//}


//package qq
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import java.util.Scanner
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val arr = Array(n) { Pair(scanner.nextLong(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val v = ArrayList<Long>()
    val res = LongArray(n)
    for (i in 0 until n) {
        res[arr[i].second] = v.sum() + c[arr[i].second]
        if (v.isEmpty() || c[arr[i].second] > v[0]) {
            v.add(c[arr[i].second])
            v.sort()
            if (v.size > k)
                v.removeAt(0)
        }
    }
    res.forEach { print("$it ") }
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val p = Array<Pair<Int, Int>>(n) { Pair(scanner.nextInt(), it) }.sortedBy { it.first }
    val c = LongArray(n) { scanner.nextLong() }
    val Q = LongArray(k + 1) { -1 }
    val res = LongArray(n)
    p.forEach {
        Q[0] = c[it.second]
        for (i in 0..k)
            if (Q[i] != -1L)
                res[it.second] += Q[i];
        Q.sort()
    }
    res.forEach { print("$it ") }

}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}
//class Pair(var a: Int, var b: Int): Comparable<Pair> {
//    override fun compareTo(other: Pair): Int {
//        return b - a - other.b + other.a
//    }
//}


import java.util.*

class Knight : Comparable<Knight> {
    override fun compareTo(other: Knight): Int {
        return force - other.force
    }

    var money: Int = 0
    var index: Int = 0
    var force: Int = 0
}

fun main(args: Array<String>) {
    var temp = readLine()!!.split(" ")
    val n = temp[0].toInt()
    val k = temp[1].toInt()
    val knights = Array(n, { _ -> Knight()})
    temp = readLine()!!.split(" ")
    for (i in 0 until n) {
        knights[i].force = temp[i].toInt()
        knights[i].index = i
    }
    temp = readLine()!!.split(" ")
    for (i in 0 until n) {
        knights[i].money = temp[i].toInt()
    }
    Arrays.sort(knights)
    val moneyOfKnightsToKill = mutableListOf<Long>()
    var sumMoneyOfKnightsToKill = 0L
    val answer = LongArray(n)
    for (i in 0 until n) {
        val curMoney = knights[i].money.toLong()
        answer[knights[i].index] = curMoney + sumMoneyOfKnightsToKill
        if (k == 0) continue
        if (moneyOfKnightsToKill.size < k) {
            moneyOfKnightsToKill.add(curMoney)
            sumMoneyOfKnightsToKill += curMoney
        } else {
            val min = moneyOfKnightsToKill.min()!!
            if (min < curMoney) {
                moneyOfKnightsToKill.remove(min)
                moneyOfKnightsToKill.add(curMoney)
                sumMoneyOfKnightsToKill += (curMoney - min)
            }
        }
    }
    for (i in answer) {
        print("$i ")
    }
}


import java.util.*

class Knight : Comparable<Knight> {
    override fun compareTo(other: Knight): Int {
        return force - other.force
    }

    var money: Int = 0
    var index: Int = 0
    var force: Int = 0
}

fun main(args: Array<String>) {
    var temp = readLine()!!.split(" ")
    val n = temp[0].toInt()
    val k = temp[1].toInt()
    val knights = Array(n, { _ -> Knight()})
    temp = readLine()!!.split(" ")
    for (i in 0 until n) {
        knights[i].force = temp[i].toInt()
        knights[i].index = i
    }
    temp = readLine()!!.split(" ")
    for (i in 0 until n) {
        knights[i].money = temp[i].toInt()
    }
    Arrays.sort(knights)
    val moneyOfKnightsToKill = TreeSet<Long>()
    var sumMoneyOfKnightsToKill = 0L
    val answer = LongArray(n)
    for (i in 0 until n) {
        val curMoney = knights[i].money.toLong()
        answer[knights[i].index] = curMoney + sumMoneyOfKnightsToKill
        if (k == 0) continue
        if (moneyOfKnightsToKill.size < k) {
            moneyOfKnightsToKill.add(curMoney)
            sumMoneyOfKnightsToKill += curMoney
        } else {
            val min = moneyOfKnightsToKill.min()!!
            if (min < curMoney) {
                moneyOfKnightsToKill.remove(min)
                moneyOfKnightsToKill.add(curMoney)
                sumMoneyOfKnightsToKill += (curMoney - min)
            }
        }
    }
    for (i in answer) {
        print("$i ")
    }
}


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")

import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.PriorityQueue
import java.util.StringTokenizer
import java.util.TreeMap
import kotlin.math.*
import kotlin.random.*
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
    val n = readInt()
    val k = readInt()
    val Kn = run {
        val P = readIntArray(n)
        MutableList(n) { i ->
            Knight(i, P[i], readInt())
        }.also { it.sortBy { it.p } }
    }

    val G = PriorityQueue<Knight>(11, compareBy { it.c })
    var gsum = 0L
    val ans = LongArray(n)

    for(kn in Kn) {
        G.add(kn)
        gsum += kn.c
        ans[kn.i] = gsum
        if(G.size > k) {
            gsum -= G.remove().c
        }
    }

    println(ans.joinToString(" "))
}

data class Knight(val i: Int, val p: Int, val c: Int)

/** IO code start */
//@JvmField val INPUT = File("input.txt").inputStream()
//@JvmField val OUTPUT = File("output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

@JvmField val _reader = INPUT.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/** shuffles and sort overrides to avoid quicksort attacks */
private inline fun <T> _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {
    // Fisher-Yates shuffle algorithm
    for (i in size - 1 downTo 1) {
        val j = rnd.nextInt(i + 1)
        val temp = get(i)
        set(i, get(j))
        set(j, temp)
    }
}

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

fun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun IntArray.sort() { shuffle(); _sort() }
fun IntArray.sortDescending() { shuffle(); _sortDescending() }

fun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun LongArray.sort() { shuffle(); _sort() }
fun LongArray.sortDescending() { shuffle(); _sortDescending() }

fun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun DoubleArray.sort() { shuffle(); _sort() }
fun DoubleArray.sortDescending() { shuffle(); _sortDescending() }

fun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T: Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T: Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T: Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T: Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

fun `please stop removing these imports IntelliJ`() {
    iprintln(max(1, 2))
}


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")

import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.PriorityQueue
import java.util.StringTokenizer
import java.util.TreeMap
import kotlin.math.*
import kotlin.random.*
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
    val n = readInt()
    val k = readInt()
    val Kn = run {
        val P = readIntArray(n)
        val C = readIntArray(n)
        MutableList(n) { i ->
            Knight(i, P[i], C[i])
        }.also { it.sortBy { it.p } }
    }

    val G = PriorityQueue<Knight>(11, compareBy { it.c })
    var gsum = 0L
    val ans = LongArray(n)

    for(kn in Kn) {
        G.add(kn)
        gsum += kn.c
        ans[kn.i] = gsum
        if(G.size > k) {
            gsum -= G.remove().c
        }
    }

    println(ans.joinToString(" "))
}

data class Knight(val i: Int, val p: Int, val c: Int)

/** IO code start */
//@JvmField val INPUT = File("input.txt").inputStream()
//@JvmField val OUTPUT = File("output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

@JvmField val _reader = INPUT.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/** shuffles and sort overrides to avoid quicksort attacks */
private inline fun <T> _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {
    // Fisher-Yates shuffle algorithm
    for (i in size - 1 downTo 1) {
        val j = rnd.nextInt(i + 1)
        val temp = get(i)
        set(i, get(j))
        set(j, temp)
    }
}

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

fun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun IntArray.sort() { shuffle(); _sort() }
fun IntArray.sortDescending() { shuffle(); _sortDescending() }

fun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun LongArray.sort() { shuffle(); _sort() }
fun LongArray.sortDescending() { shuffle(); _sortDescending() }

fun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun DoubleArray.sort() { shuffle(); _sort() }
fun DoubleArray.sortDescending() { shuffle(); _sortDescending() }

fun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T: Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T: Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T: Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T: Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

fun `please stop removing these imports IntelliJ`() {
    iprintln(max(1, 2))
}


#include<stdio.h>
#include<stdlib.h>
#define	LLD	"%lld"
int p[100007],c[100007],n,k;
int ix_p[100007],ix_c[100007];
int x[10],l;
long long r[100007];
int qdiff_p(const void *x,const void *y){
	return p[*(int *)x]>p[*(int *)y]?-1:1;
}
int qdiff_c(const void *x,const void *y){
	return c[*(int *)x]>c[*(int *)y]?-1:1;
}
void cat(int j){
	int i;
	long long r_;
	for(i=0;i<k;i++){
		if(p[x[i]]>=p[j]){
			while(l<n&&p[ix_c[l]]>=p[j])l++;
			if(l<n){
				x[i]=ix_c[l];
				l++;
			}
		}
	}
	r_=0;
	for(i=0;i<k;i++){
		if(p[x[i]]<p[j]){
			r_+=c[x[i]];
		}
	}
	r[j]=r_+c[j];
}
void run(){
	int i;
	while(scanf("%d%d",&n,&k)!=EOF){
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
		}
		for(i=0;i<n;i++){
			scanf("%d",&c[i]);
		}
		for(i=0;i<n;i++){
			ix_p[i]=i;
		}
		qsort(ix_p,n,sizeof(ix_p[0]),qdiff_p);
		for(i=0;i<n;i++){
			ix_c[i]=i;
		}
		qsort(ix_c,n,sizeof(ix_c[0]),qdiff_c);
		for(l=0;l<k;l++){
			x[l]=ix_c[l];
		}
		for(i=0;i<n;i++){
			cat(ix_p[i]);
		}
		for(i=0;i<n;i++){
			printf(LLD" ",r[i]);
		}
		printf("\n");
	}
}
main(){
#ifndef	ONLINE_JUDGE
	freopen("4882b_min.in","rb",stdin);
	freopen("4882b_.out","wb",stdout);
#endif
	run();
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <stdbool.h>
int n,m,i,b[105],j,min,mini;
long long s[100005],ans[100005],sum;
struct u
{
	int a,c,b;
}a[100005];

int cmp(const void *x,const void *y)
{
	return ((struct u *)x)->a-((struct u *)y)->a;
}

int main()
{
	scanf("%d %d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i].a);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i].c);
		a[i].b=i;
	}
	qsort(&a[1],n,sizeof(struct u),cmp);
	for (i=1,s[0]=0;i<=m+1;i++) s[i]=(long long) s[i-1]+a[i].c;
	for (i=1,sum=0;i<=m;i++)
	{
		b[i]=a[i].c;
		sum+=b[i];
	}
	for (i=1;i<=n;i++)
	if (i>m+1)
	{
		for (j=1,min=INT_MAX;j<=m;j++)
		if (b[j]<min)
		{
			min=b[j];
			mini=j;
		}
		if (a[i-1].c>min)
		{
			b[mini]=a[i-1].c;
			sum=sum-min+b[mini];
		}
		ans[a[i].b]=sum+a[i].c;
	}
	else ans[a[i].b]=s[i];
	for (i=1;i<=n;i++) printf("%lld ",ans[i]);
	return 0;
}


#include<stdio.h>
#include<math.h>
void insertionsort(long int a[ ],long int start,long int end)
{
	long int i,j,key;
	for(i=start+1;i<=end;i++)
	{
		key=a[i];
		j=i-1;
		while(j>=start && a[j]>key)
		{
			a[j+1]=a[j];
			j=j-1;
		}
		a[j+1]=key;
	}
}
void merge(long int arr[],long int ar[], long int l, long int m, long int r)
{
    long int i, j, k;
    long int n1 = m - l + 1;
    long int n2 =  r - m;

    long int L[n1],R[n2],a[n1],b[n2];

    for (i = 0; i < n1; i++)
       { L[i] = arr[l + i]; a[i] = ar[l + i];}
    for (j = 0; j < n2; j++)
      {  R[j] = arr[m + 1+ j]; b[j] = ar[m + 1+ j];}

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            ar[k] = a[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            ar[k] = b[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        ar[k] = a[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        ar[k] = b[j];
        j++;
        k++;
    }
}

void mergeSort(long int arr[],long int ar[], long int l, long int r)
{
    if (l < r)
    {
        long int m = l+(r-l)/2;

        mergeSort(arr,ar, l, m);
        mergeSort(arr,ar, m+1, r);

        merge(arr,ar, l, m, r);
    }
}
int main()
{
    long int n,k,p[100000],q[100000],e[100000],c[100000],i,j,d[100],max=0;
    scanf("%ld %ld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&p[i]);
        q[i]=p[i];
        e[i]=i;
    }
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&c[i]);
    }
    mergeSort(p,c,1,n);
    mergeSort(q,e,1,n);
    for(i=1;i<=n;i++)
    {
        if(i<=k)
        {
            d[i]=c[i];
            max+=c[i];
            q[e[i]]=max;
        }
        else if(i==k+1)
        {
            q[e[i]]=max+c[i];
        }
        else
        {
            insertionsort(d,1,k);
            if(c[i-1]>d[1])
            {
                max-=d[1];
                d[1]=c[i-1];
                max+=c[i-1];
            }
            q[e[i]]=max+c[i];
        }
    }
    for(i=1;i<=n;i++)
    {
        printf("%ld ",q[i]);
    }

}


#include<stdio.h>
#include<math.h>
void insertionsort(long long int a[ ],long long int start,long long int end)
{
	long long int i,j,key;
	for(i=start+1;i<=end;i++)
	{
		key=a[i];
		j=i-1;
		while(j>=start && a[j]>key)
		{
			a[j+1]=a[j];
			j=j-1;
		}
		a[j+1]=key;
	}
}
void merge(long long int arr[],long long int ar[], long long int l, long long int m, long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    long long int L[n1],R[n2],a[n1],b[n2];

    for (i = 0; i < n1; i++)
       { L[i] = arr[l + i]; a[i] = ar[l + i];}
    for (j = 0; j < n2; j++)
      {  R[j] = arr[m + 1+ j]; b[j] = ar[m + 1+ j];}

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            ar[k] = a[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            ar[k] = b[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        ar[k] = a[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        ar[k] = b[j];
        j++;
        k++;
    }
}

void mergeSort(long long int arr[],long long int ar[], long long int l, long long int r)
{
    if (l < r)
    {
        long long int m = l+(r-l)/2;

        mergeSort(arr,ar, l, m);
        mergeSort(arr,ar, m+1, r);

        merge(arr,ar, l, m, r);
    }
}
int main()
{
    long long int n,k,p[100000],q[100000],e[100000],c[100000],i,j,d[100],max=0;
    scanf("%lld %lld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&p[i]);
        q[i]=p[i];
        e[i]=i;
    }
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&c[i]);
    }
    if(k==0)
    {
        for(i=1;i<=n;i++)
        {
            printf("%lld ",c[i]);
        }
        goto exit ;
    }
    mergeSort(p,c,1,n);
    mergeSort(q,e,1,n);
    for(i=1;i<=n;i++)
    {
        if(i<=k)
        {
            d[i]=c[i];
            max+=c[i];
            q[e[i]]=max;
        }
        else if(i==(k+1))
        {
            q[e[i]]=max+c[i];
        }
        else
        {
            insertionsort(d,1,k);
            if(c[i-1]>d[1])
            {
                max-=d[1];
                d[1]=c[i-1];
                max+=c[i-1];
            }
            q[e[i]]=max+c[i];
        }
    }
    for(i=1;i<=n;i++)
    {
        printf("%lld ",q[i]);
    }
    exit : ;
}


#include<stdio.h>
#include<math.h>
void insertionsort(long int a[ ],long int start,long int end)
{
	long int i,j,key;
	for(i=start+1;i<=end;i++)
	{
		key=a[i];
		j=i-1;
		while(j>=start && a[j]>key)
		{
			a[j+1]=a[j];
			j=j-1;
		}
		a[j+1]=key;
	}
}
void merge(long int arr[],long int ar[], long int l, long int m, long int r)
{
    long int i, j, k;
    long int n1 = m - l + 1;
    long int n2 =  r - m;

    long int L[n1],R[n2],a[n1],b[n2];

    for (i = 0; i < n1; i++)
       { L[i] = arr[l + i]; a[i] = ar[l + i];}
    for (j = 0; j < n2; j++)
      {  R[j] = arr[m + 1+ j]; b[j] = ar[m + 1+ j];}

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            ar[k] = a[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            ar[k] = b[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        ar[k] = a[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        ar[k] = b[j];
        j++;
        k++;
    }
}

void mergeSort(long int arr[],long int ar[], long int l, long int r)
{
    if (l < r)
    {
        long int m = l+(r-l)/2;

        mergeSort(arr,ar, l, m);
        mergeSort(arr,ar, m+1, r);

        merge(arr,ar, l, m, r);
    }
}
int main()
{
    long int n,k,p[100000],q[100000],e[100000],c[100000],i,j,d[100],max=0;
    scanf("%ld %ld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&p[i]);
        q[i]=p[i];
        e[i]=i;
    }
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&c[i]);
        if(k==0)
        {
            printf("%ld ",c[i]);
        }
    }
    if(k==0)
    {
        return 0;
    }
    mergeSort(p,c,1,n);
    mergeSort(q,e,1,n);
    for(i=1;i<=n;i++)
    {
        if(i<=k)
        {
            d[i]=c[i];
            max+=c[i];
            q[e[i]]=max;
        }
        else if(i==k+1)
        {
            q[e[i]]=max+c[i];
        }
        else
        {
            insertionsort(d,1,k);
            if(c[i-1]>d[1])
            {
                max-=d[1];
                d[1]=c[i-1];
                max+=c[i-1];
            }
            q[e[i]]=max+c[i];
        }
    }
    for(i=1;i<=n;i++)
    {
        printf("%ld ",q[i]);
    }

}


#include<stdio.h>
#include<math.h>
void insertionsort(long int a[ ],long int start,long int end)
{
	long int i,j,key;
	for(i=start+1;i<=end;i++)
	{
		key=a[i];
		j=i-1;
		while(j>=start && a[j]>key)
		{
			a[j+1]=a[j];
			j=j-1;
		}
		a[j+1]=key;
	}
}
void merge(long int arr[],long int ar[], long int l, long int m, long int r)
{
    long int i, j, k;
    long int n1 = m - l + 1;
    long int n2 =  r - m;

    long int L[n1],R[n2],a[n1],b[n2];

    for (i = 0; i < n1; i++)
       { L[i] = arr[l + i]; a[i] = ar[l + i];}
    for (j = 0; j < n2; j++)
      {  R[j] = arr[m + 1+ j]; b[j] = ar[m + 1+ j];}

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            ar[k] = a[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            ar[k] = b[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        ar[k] = a[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        ar[k] = b[j];
        j++;
        k++;
    }
}

void mergeSort(long int arr[],long int ar[], long int l, long int r)
{
    if (l < r)
    {
        long int m = l+(r-l)/2;

        mergeSort(arr,ar, l, m);
        mergeSort(arr,ar, m+1, r);

        merge(arr,ar, l, m, r);
    }
}
int main()
{
    long int n,k,p[100000],q[100000],e[100000],c[100000],i,j,d[100],max=0;
    scanf("%ld %ld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&p[i]);
        q[i]=p[i];
        e[i]=i;
    }
    for(i=1;i<=n;i++)
    {
        scanf("%ld",&c[i]);
    }
    if(k==0)
    {
        for(i=1;i<=n;i++)
        {
            printf("%ld ",c[i]);
        }
        goto exit ;
    }
    mergeSort(p,c,1,n);
    mergeSort(q,e,1,n);
    for(i=1;i<=n;i++)
    {
        if(i<=k)
        {
            d[i]=c[i];
            max+=c[i];
            q[e[i]]=max;
        }
        else if(i==(k+1))
        {
            q[e[i]]=max+c[i];
        }
        else
        {
            insertionsort(d,1,k);
            if(c[i-1]>d[1])
            {
                max-=d[1];
                d[1]=c[i-1];
                max+=c[i-1];
            }
            q[e[i]]=max+c[i];
        }
    }
    for(i=1;i<=n;i++)
    {
        printf("%ld ",q[i]);
    }
    exit : ;
}


#include<stdio.h>
#include<stdlib.h>

long long int func(long long int *a,long long int l,long long int r,long long int key)
{
    long long int mid=(l+r)/2;
    if(a[mid]==key)
        return mid;
    else if(a[mid]<key)
        return func(a,mid+1,r,key);
    else
        return func(a,l,mid-1,key);
}

void insert(long long int *a,long long int key,long long int k)
{
    long long int i;
    for(i=0;i<(k-1);i++)
    {
        if(a[i+1]<key)
            a[i]=a[i+1];
        else
        {
            a[i]=key;
            return ;
        }
    }
    a[k-1]=key;
    return ;

}

void merge(long long int arr[], long long int l, long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], long long int l,long long int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    long long int n,i,k,j;
    scanf("%lld %lld",&n,&k);
    long long int *p=(long long int *)malloc(n*sizeof(long long int));
    long long int *p1=(long long int *)malloc(n*sizeof(long long int));
    long long int *c=(long long int *)malloc(n*sizeof(long long int));
    long long int *cc=(long long int *)malloc(n*sizeof(long long int));
    long long int *coin=(long long int *)malloc(n*sizeof(long long int));
    long long int *kk=(long long int *)malloc(k*sizeof(long long int));
    for(i=0;i<n;i++)
    {
        scanf("%lld",p+i);
        p1[i]=p[i];
    }

    for(i=0;i<n;i++)
    {
        scanf("%lld",c+i);
        cc[i]=c[i];
    }

    mergeSort(p1,0,n-1);
    for(i=0;i<n;i++)
        coin[func(p1,0,n-1,p[i])]=c[i];

        cc[0]=0;
        kk[0]=coin[0];
    for(i=1;i<n;i++)
    {

         if(i<k)
        {
            cc[i]=cc[i-1]+coin[i-1];
            kk[i]=coin[i];

            if(i==(k-1))
                mergeSort(kk,0,k-1);
            continue;
        }

        if(i==k)
        {
            cc[i]=cc[i-1]+ coin[i-1];
            continue;
        }

        if(coin[i-1]>kk[0])
        {
            cc[i]=cc[i-1]+coin[i-1]-kk[0];
            insert(kk,coin[i-1],k);
        }
        else
            cc[i]=cc[i-1];
    }

    for(i=0;i<n;i++)
    {
        printf("%lld ",cc[func(p1,0,n-1,p[i])]+c[i]);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

long long int func(long long int *a,long long int l,long long int r,long long int key)
{
    long long int mid=(l+r)/2;
    if(a[mid]==key)
        return mid;
    else if(a[mid]<key)
        return func(a,mid+1,r,key);
    else
        return func(a,l,mid-1,key);
}

void insert(long long int *a,long long int key,long long int k)
{
    long long int i;
    for(i=0;i<(k-1);i++)
    {
        if(a[i+1]<key)
            a[i]=a[i+1];
        else
        {
            a[i]=key;
            return ;
        }
    }
    a[k-1]=key;
    return ;

}

void merge(long long int arr[], long long int l, long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], long long int l,long long int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
       long long s int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    long long int n,i,k,j;
    scanf("%lld %lld",&n,&k);
    long long int *p=(long long int *)malloc(n*sizeof(long long int));
    long long int *p1=(long long int *)malloc(n*sizeof(long long int));
    long long int *c=(long long int *)malloc(n*sizeof(long long int));
    long long int *cc=(long long int *)malloc(n*sizeof(long long int));
    long long int *coin=(long long int *)malloc(n*sizeof(long long int));
    long long int *kk=(long long int *)malloc(k*sizeof(long long int));
    for(i=0;i<n;i++)
    {
        scanf("%lld",p+i);
        p1[i]=p[i];
    }

    for(i=0;i<n;i++)
    {
        scanf("%lld",c+i);
        cc[i]=c[i];
    }

    mergeSort(p1,0,n-1);
    for(i=0;i<n;i++)
        coin[func(p1,0,n-1,p[i])]=c[i];

        cc[0]=0;
        kk[0]=coin[0];
    for(i=1;i<n;i++)
    {

         if(i<k)
        {
            cc[i]=cc[i-1]+coin[i-1];
            kk[i]=coin[i];

            if(i==(k-1))
                mergeSort(kk,0,k-1);
            continue;
        }

        if(i==k)
        {
            cc[i]=cc[i-1]+ coin[i-1];
            continue;
        }

        if(coin[i-1]>kk[0])
        {
            cc[i]=cc[i-1]+coin[i-1]-kk[0];
            insert(kk,coin[i-1],k);
        }
        else
            cc[i]=cc[i-1];
    }

    for(i=0;i<n;i++)
    {
        printf("%lld ",cc[func(p1,0,n-1,p[i])]+c[i]);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

long long int func(long long int *a,long long int l,long long int r,long long int key)
{
    long long int mid=(l+r)/2;
    if(a[mid]==key)
        return mid;
    else if(a[mid]<key)
        return func(a,mid+1,r,key);
    else
        return func(a,l,mid-1,key);
}

void insert(long long int *a,long long int key,long long int k)
{
    long long int i;
    for(i=0;i<(k-1);i++)
    {
        if(a[i+1]<key)
            a[i]=a[i+1];
        else
        {
            a[i]=key;
            return ;
        }
    }
    a[k-1]=key;
    return ;

}

void merge(long long int arr[], long long int l, long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], long long int l,long long int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
       long long int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    long long int n,i,k,j;
    scanf("%lld %lld",&n,&k);
    long long int *p=(long long int *)malloc(n*sizeof(long long int));
    long long int *p1=(long long int *)malloc(n*sizeof(long long int));
    long long int *c=(long long int *)malloc(n*sizeof(long long int));
    long long int *cc=(long long int *)malloc(n*sizeof(long long int));
    long long int *coin=(long long int *)malloc(n*sizeof(long long int));
    long long int *kk=(long long int *)malloc(k*sizeof(long long int));
    for(i=0;i<n;i++)
    {
        scanf("%lld",p+i);
        p1[i]=p[i];
    }

    for(i=0;i<n;i++)
    {
        scanf("%lld",c+i);
        cc[i]=c[i];
    }

    if(k>0)
   {
       mergeSort(p1,0,n-1);
    for(i=0;i<n;i++)
        coin[func(p1,0,n-1,p[i])]=c[i];

        cc[0]=0;
        kk[0]=coin[0];
    for(i=1;i<n;i++)
    {

         if(i<k)
        {
            cc[i]=cc[i-1]+coin[i-1];
            kk[i]=coin[i];

            if(i==(k-1))
                mergeSort(kk,0,k-1);
            continue;
        }

        if(i==k)
        {
            cc[i]=cc[i-1]+ coin[i-1];
            continue;
        }

        if(coin[i-1]>kk[0])
        {
            cc[i]=cc[i-1]+coin[i-1]-kk[0];
            insert(kk,coin[i-1],k);
        }
        else
            cc[i]=cc[i-1];
    }

    for(i=0;i<n;i++)
    {
        printf("%lld ",cc[func(p1,0,n-1,p[i])]+c[i]);
    }
   }
   else
   {
       for(i=0;i<n;i++)
        printf("%lld ",p[i]);
   }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

long long int func(long long int *a,long long int l,long long int r,long long int key)
{
    long long int mid=(l+r)/2;
    if(a[mid]==key)
        return mid;
    else if(a[mid]<key)
        return func(a,mid+1,r,key);
    else
        return func(a,l,mid-1,key);
}

void insert(long long int *a,long long int key,long long int k)
{
    long long int i;
    for(i=0;i<(k-1);i++)
    {
        if(a[i+1]<key)
            a[i]=a[i+1];
        else
        {
            a[i]=key;
            return ;
        }
    }
    a[k-1]=key;
    return ;

}

void merge(long long int arr[], long long int l, long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], long long int l,long long int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
       long long int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    long long int n,i,k,j;
    scanf("%lld %lld",&n,&k);
    long long int *p=(long long int *)malloc(n*sizeof(long long int));
    long long int *p1=(long long int *)malloc(n*sizeof(long long int));
    long long int *c=(long long int *)malloc(n*sizeof(long long int));
    long long int *cc=(long long int *)malloc(n*sizeof(long long int));
    long long int *coin=(long long int *)malloc(n*sizeof(long long int));
    long long int *kk=(long long int *)malloc(k*sizeof(long long int));
    for(i=0;i<n;i++)
    {
        scanf("%lld",p+i);
        p1[i]=p[i];
    }

    for(i=0;i<n;i++)
    {
        scanf("%lld",c+i);
        cc[i]=c[i];
    }

    mergeSort(p1,0,n-1);
    for(i=0;i<n;i++)
        coin[func(p1,0,n-1,p[i])]=c[i];

        cc[0]=0;
        kk[0]=coin[0];
    for(i=1;i<n;i++)
    {

         if(i<k)
        {
            cc[i]=cc[i-1]+coin[i-1];
            kk[i]=coin[i];

            if(i==(k-1))
                mergeSort(kk,0,k-1);
            continue;
        }

        if(i==k)
        {
            cc[i]=cc[i-1]+ coin[i-1];
            continue;
        }

        if(coin[i-1]>kk[0])
        {
            cc[i]=cc[i-1]+coin[i-1]-kk[0];
            insert(kk,coin[i-1],k);
        }
        else
            cc[i]=cc[i-1];
    }

    for(i=0;i<n;i++)
    {
        printf("%lld ",cc[func(p1,0,n-1,p[i])]+c[i]);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

long long int func(long long int *a,long long int l,long long int r,long long int key)
{
    long long int mid=(l+r)/2;
    if(a[mid]==key)
        return mid;
    else if(a[mid]<key)
        return func(a,mid+1,r,key);
    else
        return func(a,l,mid-1,key);
}

void insert(long long int *a,long long int key,long long int k)
{
    long long int i;
    for(i=0;i<(k-1);i++)
    {
        if(a[i+1]<key)
            a[i]=a[i+1];
        else
        {
            a[i]=key;
            return ;
        }
    }
    a[k-1]=key;
    return ;

}

void merge(long long int arr[], long long int l, long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 =  r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[], long long int l,long long int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
       long long int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    long long int n,i,k,j;
    scanf("%lld %lld",&n,&k);
    long long int *p=(long long int *)malloc(n*sizeof(long long int));
    long long int *p1=(long long int *)malloc(n*sizeof(long long int));
    long long int *c=(long long int *)malloc(n*sizeof(long long int));
    long long int *cc=(long long int *)malloc(n*sizeof(long long int));
    long long int *coin=(long long int *)malloc(n*sizeof(long long int));
    long long int *kk=(long long int *)malloc(k*sizeof(long long int));
    for(i=0;i<n;i++)
    {
        scanf("%lld",p+i);
        p1[i]=p[i];
    }

    for(i=0;i<n;i++)
    {
        scanf("%lld",c+i);
        cc[i]=c[i];
    }

    if(k>0)
   {
       mergeSort(p1,0,n-1);
    for(i=0;i<n;i++)
        coin[func(p1,0,n-1,p[i])]=c[i];

        cc[0]=0;
        kk[0]=coin[0];
    for(i=1;i<n;i++)
    {

         if(i<k)
        {
            cc[i]=cc[i-1]+coin[i-1];
            kk[i]=coin[i];

            if(i==(k-1))
                mergeSort(kk,0,k-1);
            continue;
        }

        if(i==k)
        {
            cc[i]=cc[i-1]+ coin[i-1];
            continue;
        }

        if(coin[i-1]>kk[0])
        {
            cc[i]=cc[i-1]+coin[i-1]-kk[0];
            insert(kk,coin[i-1],k);
        }
        else
            cc[i]=cc[i-1];
    }

    for(i=0;i<n;i++)
    {
        printf("%lld ",cc[func(p1,0,n-1,p[i])]+c[i]);
    }
   }
   else
   {
       for(i=0;i<n;i++)
        printf("%lld ",c[i]);
   }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
struct k { int p,c,i; };

int comp(const void *a, const void *b){
	return ((int) ((struct k*) a)->p) - ((int) ((struct k*) b)->p);
}
void insert(int *heap, int size, int element){
    heap[size] = element;
    while (size > 0 && heap[(size - 1)/2] > element){
        heap[size] = heap[(size - 1)/2];
        heap[(size-1)/2] = element;
        size = (size - 1)/2;
    }
}

void del(int *heap, int size){
    if (size == 0){
        return;
    }
    heap[0] = heap[size - 1];
    size--;
    int index = 0;
    while (index < size){
        int mindx = index*2 + 1;
        if (mindx + 1 < size && heap[mindx + 1] < heap[mindx]){
            mindx++;
        }
        if ((mindx >= size) || (heap[mindx] > heap[index])){
            break;
        }
        else{
            int temp = heap[index];
            heap[index] = heap[mindx];
            heap[mindx] = temp;
        }
        index = mindx;
    }
}

int main(){

	int n,k,i;
	scanf("%d %d",&n,&k);
	struct k arr[n];
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].p));
		arr[i].i = i;
	}
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].c));
	}

	qsort(arr,n,sizeof(struct k),comp);

	int heap[k], size = 0;
	unsigned long long sum = 0, ans[n];

	for (i = 0; i < n; i++){

		ans[arr[i].i] = sum + arr[i].c;

		if (size < k){
			insert(heap,size,arr[i].c);
			size++;
			sum += arr[i].c;
		}

		else if (arr[i].c > heap[0]){

			sum -= heap[0];

			del(heap,size);
			size--;

			insert(heap,size,arr[i].c);
			size++;
			sum += arr[i].c;

		}

	}

	for (i = 0; i < n; i++){

		if (i > 0){
			printf(" ");
		}

		printf("%I64d",ans[i]);
	}
	printf("\n");

}


#include <stdio.h>
#include <stdlib.h>

struct k { int i,p,c; };

int comp(const void *a, const void *b){
	return ((int) ((struct k*) a)->c) - ((int) ((struct k*) b)->c);
}

int main(){

	int n,k,i;
	scanf("%d %d",&n,&k);
	struct k arr[n];
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].p));
		arr[i].i = i;
	}
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].c));
	}

	qsort(arr,n,sizeof(struct k),comp);

	int ans[n];

	for (i = 0; i < n; i++){
		int j = n - 1, coins = 0, killed = 0;

		while (j >= 0 && killed < k){

			if (arr[j].p < arr[i].p){
				coins += arr[j].c;
				killed++;
			}
			j--;
		}

		ans[arr[i].i] = arr[i].c + coins;

	}

	for (i = 0; i < n; i++){

		if (i > 0){
			printf(" ");
		}

		printf("%d",ans[i]);

		if (i == n - 1){
			printf("\n");
		}
	}

}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
struct k { int p,c,i; };

int comp(const void *a, const void *b){
	return ((int) ((struct k*) a)->p) - ((int) ((struct k*) b)->p);
}
void insert(int *heap, int size, int element){
    heap[size] = element;
    while (size > 0 && heap[(size - 1)/2] > element){
        heap[size] = heap[(size - 1)/2];
        heap[(size-1)/2] = element;
        size = (size - 1)/2;
    }
}

void del(int *heap, int size){
    if (size == 0){
        return;
    }
    heap[0] = heap[size - 1];
    size--;
    int index = 0;
    while (index < size){
        int mindx = index*2 + 1;
        if (mindx + 1 < size && heap[mindx + 1] < heap[mindx]){
            mindx++;
        }
        if ((mindx >= size) || (heap[mindx] > heap[index])){
            break;
        }
        else{
            int temp = heap[index];
            heap[index] = heap[mindx];
            heap[mindx] = temp;
        }
        index = mindx;
    }
}

int main(){

	int n,k,i;
	scanf("%d %d",&n,&k);
	struct k arr[n];
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].p));
		arr[i].i = i;
	}
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].c));
	}

	qsort(arr,n,sizeof(struct k),comp);

	int heap[k], size = 0;
	unsigned long long sum = 0, ans[n];

	for (i = 0; i < n; i++){

		ans[arr[i].i] = sum + arr[i].c;

		if (size < k){
			insert(heap,size,arr[i].c);
			size++;
			sum += arr[i].c;
		}

		else if (size > 0 && arr[i].c > heap[0]){

			sum -= heap[0];

			del(heap,size);
			size--;

			insert(heap,size,arr[i].c);
			size++;
			sum += arr[i].c;

		}

	}

	for (i = 0; i < n; i++){

		if (i > 0){
			printf(" ");
		}

		printf("%I64d",ans[i]);
	}
	printf("\n");

}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
struct k { int i,p,c; };

int comp(const void *a, const void *b){
	return ((int) ((struct k*) a)->c) - ((int) ((struct k*) b)->c);
}

int main(){

	int n,k,i;
	scanf("%d %d",&n,&k);
	struct k arr[n];
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].p));
		arr[i].i = i;
	}
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].c));
	}

	qsort(arr,n,sizeof(struct k),comp);

	unsigned long long ans[n];

	for (i = 0; i < n; i++){
		int j = n - 1, killed = 0;
		unsigned long long coins = 0;

		while (j >= 0 && killed < k){

			if (arr[j].p < arr[i].p){
				coins += arr[j].c;
				killed++;
			}
			j--;
		}

		ans[arr[i].i] = arr[i].c + coins;

	}

	for (i = 0; i < n; i++){

		if (i > 0){
			printf(" ");
		}

		printf("%I64d",ans[i]);

	}
	printf("\n");

}


#include <stdio.h>
#include <stdlib.h>

struct k { int i,p,c; };

int comp(const void *a, const void *b){
	return ((int) ((struct k*) a)->c) - ((int) ((struct k*) b)->c);
}

int main(){

	int n,k,i;
	scanf("%d %d",&n,&k);
	struct k arr[n];
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].p));
		arr[i].i = i;
	}
	for (i = 0; i < n; i++){
		scanf("%d",&(arr[i].c));
	}

	qsort(arr,n,sizeof(struct k),comp);

	int ans[n];

	for (i = 0; i < n; i++){
		int j = n - 1, coins = 0, killed = 0;

		while (j >= 0 && killed < k){

			if (arr[j].p < arr[i].p){
				coins += arr[j].c;
				killed++;
			}
			j--;
		}

		ans[arr[i].i] = arr[i].c + coins;

	}

	for (i = 0; i < n; i++){

		if (i > 0){
			printf(" ");
		}

		printf("%d",ans[i]);

	}
	printf("\n");

}


import java.io.*;
import java.util.*;

public class A {
    public static class Knight implements Comparable<Knight> {
        long power = 0;
        long coin = 0;
        int ind = 0;
        long answer = 0;

        Knight(long power, long coin, int ind) {
            this.power = power;
            this.coin = coin;
            this.ind = ind;
            this.answer = coin;
        }

        @Override
        public int compareTo(Knight o) {
            return power < o.power ? -1 : 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        List<Knight> list = new ArrayList<>(n);
        List<Long> power = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            power.add(scanner.nextLong());
        }
        for (int i = 0; i < n; i++) {
            long c = scanner.nextLong();
            list.add(new Knight(power.get(i), c, i));
        }

        Collections.sort(list);

        Set<Knight> set = new TreeSet<>(new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                if (o1.coin != o2.coin) {
                    return o1.coin > o2.coin ? -1 : 1;
                }
                return 0;
            }
        });

        for (int i = 0; i < n; i++) {
            int j = 0;
            for (Knight knight : set) {
                if (j == k) {
                    break;
                }
                list.get(i).answer += knight.coin;
                j++;
                if (j == k) {
                    break;
                }
            }
            set.add(list.get(i));
        }

        Collections.sort(list, new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                return o1.ind < o2.ind ? -1 : 1;
            }
        });

        for (Knight knight : list) {
            System.out.print(knight.answer + " ");
        }
    }
}


import java.io.*;
import java.util.*;

public class A {
    public static class Knight implements Comparable<Knight> {
        long power = 0;
        long coin = 0;
        int ind = 0;
        long answer = 0;

        Knight(long power, long coin, int ind) {
            this.power = power;
            this.coin = coin;
            this.ind = ind;
            this.answer = coin;
        }

        @Override
        public int compareTo(Knight o) {
            return power < o.power ? -1 : 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        List<Knight> list = new ArrayList<>(n);
        List<Long> power = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            power.add(scanner.nextLong());
        }
        for (int i = 0; i < n; i++) {
            long c = scanner.nextLong();
            list.add(new Knight(power.get(i), c, i));
        }

        Collections.sort(list);

        Set<Knight> set = new TreeSet<>(new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                if (o1.coin != o2.coin) {
                    return o1.coin > o2.coin ? -1 : 1;
                } else {
                    return o1.power < o2.power ? -1 : 1;
                }
            }
        });

        for (int i = 0; i < n; i++) {
            int j = 0;
            for (Knight knight : set) {
                if (j == k) {
                    break;
                }
                list.get(i).answer += knight.coin;
                j++;
                if (j == k) {
                    break;
                }
            }
            set.add(list.get(i));
        }

        Collections.sort(list, new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                return o1.ind < o2.ind ? -1 : 1;
            }
        });

        for (Knight knight : list) {
            System.out.print(knight.answer + " ");
        }
    }
}


import java.io.*;
import java.util.*;

public class A {
    public static class Knight implements Comparable<Knight> {
        long power = 0;
        long coin = 0;
        int ind = 0;
        long answer = 0;

        Knight(long power, long coin, int ind) {
            this.power = power;
            this.coin = coin;
            this.ind = ind;
            this.answer = coin;
        }

        @Override
        public int compareTo(Knight o) {
            return power < o.power ? -1 : 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        List<Knight> list = new ArrayList<>(n);
        List<Long> power = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            power.add(scanner.nextLong());
        }
        for (int i = 0; i < n; i++) {
            long c = scanner.nextLong();
            list.add(new Knight(power.get(i), c, i));
        }

        Collections.sort(list);

        Set<Knight> set = new TreeSet<>(new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                if (o1.coin != o2.coin) {
                    return o1.coin > o2.coin ? -1 : 1;
                }
                return 0;
            }
        });

        for (int i = 0; i < n; i++) {
            int j = 0;
            for (Knight knight : set) {
                list.get(i).answer += knight.coin;
                j++;
                if (j == k) {
                    break;
                }
            }
            set.add(list.get(i));
        }

        Collections.sort(list, new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                return o1.ind < o2.ind ? -1 : 1;
            }
        });

        for (Knight knight : list) {
            System.out.print(knight.answer + " ");
        }
    }
}


import java.io.*;
import java.util.*;

public class A {
    public static class Knight implements Comparable<Knight> {
        long power = 0;
        long coin = 0;
        int ind = 0;
        long answer = 0;

        Knight(long power, long coin, int ind) {
            this.power = power;
            this.coin = coin;
            this.ind = ind;
            this.answer = coin;
        }

        @Override
        public int compareTo(Knight o) {
            return power < o.power ? -1 : 1;
        }
    }

    public static void main(String[] args) throws IOException{
        //Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(reader.readLine());
        List<Knight> list = new ArrayList<>(n);
        List<Long> power = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            power.add(Long.parseLong(st.nextToken()));
        }
        st = new StringTokenizer(reader.readLine());
        for (int i = 0; i < n; i++) {
            long c = Long.parseLong(st.nextToken());
            list.add(new Knight(power.get(i), c, i));
        }

        Collections.sort(list);

        Set<Knight> set = new TreeSet<>(new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                if (o1.coin != o2.coin) {
                    return o1.coin > o2.coin ? -1 : 1;
                } else {
                    return o1.power < o2.power ? -1 : 1;
                }
            }
        });

        for (int i = 0; i < n; i++) {
            int j = 0;
            for (Knight knight : set) {
                if (j == k) {
                    break;
                }
                list.get(i).answer += knight.coin;
                j++;
                if (j == k) {
                    break;
                }
            }
            set.add(list.get(i));
        }

        Collections.sort(list, new Comparator<Knight>() {
            @Override
            public int compare(Knight o1, Knight o2) {
                return o1.ind < o2.ind ? -1 : 1;
            }
        });

        for (Knight knight : list) {
            System.out.print(knight.answer + " ");
        }
    }
}


import java.io.*;
import java.util.*;

public class Dpairs
{

	public static void main(String[] args)throws IOException
	{

		BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

		String s[]=ob.readLine().split(" ");
		int n=Integer.parseInt(s[0]);
		int k=Integer.parseInt(s[1]);

		String str[]=ob.readLine().split(" ");
		List<Integer> p=new ArrayList<>();
		Map<Integer,Integer> index=new HashMap<>();

		for(int i=0;i<n;i++)
		{
			p.add(Integer.parseInt(str[i]));
			index.put(i,p.get(i));
		}

		String str1[]=ob.readLine().split(" ");

		Map<Integer,Integer> map=new HashMap<>();
		for(int i=0;i<n;i++)
		{
			int key=p.get(i);
			int value=Integer.parseInt(str1[i]);
			map.put(key, value);
		}

		Collections.sort(p);

		Queue<Integer> coins=new PriorityQueue<>(Collections.reverseOrder());

		Map<Integer,Integer> xyz=new HashMap<>();

		for(int i=0;i<n;i++)
		{
			List<Integer> q=new ArrayList<>();
			int x=p.get(i);

//			System.out.println("x = "+x);

			int org=map.get(x);
			int temp=map.get(x);
			int j=0;
			int m=i;
			while(j<k && m>=0)
			{
//				System.out.println("j , m = "+j+" "+m);
				if(!coins.isEmpty())
				{
					int pl=coins.poll();
//					System.out.println("poll = "+pl);
					q.add(pl);
					temp+=pl;
				}
				j++;
				m--;
			}
			coins.add(org);
			for(int o=0;o<q.size();o++)
				coins.add(q.get(o));

			xyz.put(x, temp);

//			System.out.println("x , temp = "+x+" "+temp);
//
//			System.out.println("***********");
		}

		for(int i=0;i<n;i++)
		{
			int t1=index.get(i);
			int val=xyz.get(t1);
			System.out.print(val+" ");
		}
	}
}


import java.io.*;
import java.util.*;

public class Dpairs
{

	public static void main(String[] args)throws IOException
	{

		BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

		String s[]=ob.readLine().split(" ");
		int n=Integer.parseInt(s[0]);
		int k=Integer.parseInt(s[1]);

		String str[]=ob.readLine().split(" ");
		List<Integer> p=new ArrayList<>();
		Map<Integer,Integer> index=new HashMap<>();  // power to index

		for(int i=0;i<n;i++)
		{
			p.add(Integer.parseInt(str[i]));
			index.put(p.get(i),i);
		}

		String str1[]=ob.readLine().split(" ");

		Map<Integer,Integer> map=new HashMap<>(); // power to coins
		for(int i=0;i<n;i++)
		{
			int key=p.get(i);
			int value=Integer.parseInt(str1[i]);
			map.put(key, value);
		}

		if(k==0)
		{
			for(int i=0;i<n;i++)
				System.out.print(Integer.parseInt(str1[i])+" ");

			return;
		}
		Map<Integer,Integer> idx_cn=new HashMap<>(); // index to coin
		Collections.sort(p);
		int cn[]=new int[k];

		int sum=0;
		for(int i=0;i<k;i++)
		{
			int key=p.get(i);
			int val=map.get(key);
			cn[i]=val;
			sum+=val;
			int id=index.get(key);
			idx_cn.put(id, sum);
		}
		Arrays.sort(cn);

//		System.out.print("cn = ");
//		for(int i=0;i<k;i++) System.out.print(cn[i]+" ");
//		System.out.println();

		for(int i=k;i<n;i++)
		{
			int key=p.get(i);
			int id=index.get(key);
			int val=map.get(key);
			idx_cn.put(id, sum+map.get(key));

			if(val>cn[0])
			{
				sum-=cn[0];
				sum+=val;
				int j=0;
				while(cn[j]<val && j<k-1)
				{
					cn[j]=cn[j+1];
					j++;
				}
				cn[j]=val;
			}
//			System.out.print("cn = ");
//			for(int l=0;l<k;l++) System.out.print(cn[l]+" ");
//			System.out.println("**********");
		}
		for(int i=0;i<n;i++)
			System.out.print(idx_cn.get(i)+" ");
	}
}


import java.io.*;
import java.util.*;

public class Dpairs
{

	public static void main(String[] args)throws IOException
	{

		BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

		String s[]=ob.readLine().split(" ");
		int n=Integer.parseInt(s[0]);
		int k=Integer.parseInt(s[1]);

		String str[]=ob.readLine().split(" ");
		List<Integer> p=new ArrayList<>();
		Map<Integer,Integer> index=new HashMap<>();  // power to index

		for(int i=0;i<n;i++)
		{
			p.add(Integer.parseInt(str[i]));
			index.put(p.get(i),i);
		}

		String str1[]=ob.readLine().split(" ");

		Map<Integer,Integer> map=new HashMap<>(); // power to coins
		for(int i=0;i<n;i++)
		{
			int key=p.get(i);
			int value=Integer.parseInt(str1[i]);
			map.put(key, value);
		}

		if(k==0)
		{
			for(int i=0;i<n;i++)
				System.out.print(Integer.parseInt(str1[i])+" ");

			return;
		}
		Map<Integer,Integer> idx_cn=new HashMap<>(); // index to coin
		Collections.sort(p);
		Queue<Integer> cn=new PriorityQueue<>();

		int sum=0;
		for(int i=0;i<k;i++)
		{
			int key=p.get(i);
			int val=map.get(key);
			cn.add(val);
			sum+=val;
			int id=index.get(key);
			idx_cn.put(id, sum);
		}

//		System.out.print("cn = ");
//		for(int i=0;i<k;i++) System.out.print(cn[i]+" ");
//		System.out.println();

		for(int i=k;i<n;i++)
		{
			int key=p.get(i);
			int id=index.get(key);
			int val=map.get(key);
			idx_cn.put(id, sum+map.get(key));

			int cn0=cn.peek();
			if(val>cn0)
			{
				sum-=cn0;
				sum+=val;
				cn.poll();
				cn.add(val);
			}
//			System.out.print("cn = ");
//			for(int l=0;l<k;l++) System.out.print(cn[l]+" ");
//			System.out.println("**********");
		}
		for(int i=0;i<n;i++)
			System.out.print(idx_cn.get(i)+" ");
	}
}


import java.io.*;
import java.util.*;

public class Dpairs
{

	public static void main(String[] args)throws IOException
	{

		BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

		String s[]=ob.readLine().split(" ");
		int n=Integer.parseInt(s[0]);
		int k=Integer.parseInt(s[1]);

		String str[]=ob.readLine().split(" ");
		List<Integer> p=new ArrayList<>();
		Map<Integer,Integer> index=new HashMap<>();  // power to index

		for(int i=0;i<n;i++)
		{
			p.add(Integer.parseInt(str[i]));
			index.put(p.get(i),i);
		}

		String str1[]=ob.readLine().split(" ");

		Map<Integer,Integer> map=new HashMap<>(); // power to coins
		for(int i=0;i<n;i++)
		{
			int key=p.get(i);
			int value=Integer.parseInt(str1[i]);
			map.put(key, value);
		}

		if(k==0)
		{
			for(int i=0;i<n;i++)
				System.out.print(Integer.parseInt(str1[i])+" ");

			return;
		}
		Map<Integer,Long> idx_cn=new HashMap<>(); // index to coin
		Collections.sort(p);
		Queue<Integer> cn=new PriorityQueue<>();

		long sum=0L;
		for(int i=0;i<k;i++)
		{
			int key=p.get(i);
			int val=map.get(key);
			cn.add(val);
			sum+=(long)val;
			int id=index.get(key);
			idx_cn.put(id, sum);
		}

//		System.out.print("cn = ");
//		for(int i=0;i<k;i++) System.out.print(cn[i]+" ");
//		System.out.println();

		for(int i=k;i<n;i++)
		{
			int key=p.get(i);
			int id=index.get(key);
			int val=map.get(key);
			idx_cn.put(id, sum+(long)map.get(key));

			long cn0=(long)cn.peek();
			if(val>cn0)
			{
				sum-=cn0;
				sum+=(long)val;
				cn.poll();
				cn.add(val);
			}
//			System.out.print("cn = ");
//			for(int l=0;l<k;l++) System.out.print(cn[l]+" ");
//			System.out.println("**********");
		}
		for(int i=0;i<n;i++)
			System.out.print(idx_cn.get(i)+" ");
	}
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.TreeSet;

public class Main{
    public static class kn{
	int p,c,i;
	long ans;
	kn(int p, int c,int i, long ans){
	    this.p = p;
	    this.c = c;
	    this.i = i;
	    this.ans = ans;
	}
    }

    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	int n = Integer.parseInt(s[0]);
	int k = Integer.parseInt(s[1]);
	String p[] = br.readLine().split(" ");
	String c[] = br.readLine().split(" ");
	kn po[] = new kn[n];
	int a = 0, b = 0;
	for(int i = 0;i<n;i++){
	    a = Integer.parseInt(p[i]);
	    b = Integer.parseInt(c[i]);
	    po[i] = new kn(a,b,i,0);
	}
	Arrays.sort(po,(x,y)->{return x.p-y.p;});
	int ans[] = new int[n];
	long ac = 0;
	TreeSet<Integer> sum = new TreeSet<Integer>();
	for(int i = 0; i<n;i++){
	    if(i<=k){
		ac+=po[i].c;
		sum.add(po[i].c);
		po[i].ans = ac;
	    }else{
		ac-=sum.pollFirst();;
		ac+=po[i].c;
		po[i].ans = ac;
		po[i].ans = (ac);
		sum.add(po[i].c);
	    }
	}
	Arrays.sort(po,(x,y)->{return x.i-y.i;});
	for(int i = 0; i<n;i++){
	    out.print(po[i].ans+" ");
	}
	out.close();
    }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.TreeSet;

public class Main{
    public static class kn{
	int p,c,i,ans;
	kn(int p, int c,int i, int ans){
	    this.p = p;
	    this.c = c;
	    this.i = i;
	    this.ans = ans;
	}
    }

    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	int n = Integer.parseInt(s[0]);
	int k = Integer.parseInt(s[1]);
	String p[] = br.readLine().split(" ");
	String c[] = br.readLine().split(" ");
	kn po[] = new kn[n];
	int a = 0, b = 0;
	for(int i = 0;i<n;i++){
	    a = Integer.parseInt(p[i]);
	    b = Integer.parseInt(c[i]);
	    po[i] = new kn(a,b,i,0);
	}
	Arrays.sort(po,(x,y)->{return x.p-y.p;});
	int ans[] = new int[n];
	int ac = 0;
	TreeSet<Integer> sum = new TreeSet<Integer>();
	for(int i = 0; i<n;i++){
	    ac+=po[i].c;
	    sum.add(po[i].c);
	    if(i<=k){
		po[i].ans = ac;
		//		out.print(ans[i]+" ");
	    }else{
		ac-=sum.pollFirst();
		po[i].ans = (ac);
		//out.println((ans[i]-ans[i-k-1])+" ");
	    }
	}
	Arrays.sort(po,(x,y)->{return x.i-y.i;});
	for(int i = 0; i<n;i++){
	    out.print(po[i].ans+" ");
	}
	out.close();
    }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main{
    public static class kn{
	int p,c,i,ans;
	kn(int p, int c,int i, int ans){
	    this.p = p;
	    this.c = c;
	    this.i = i;
	    this.ans = ans;
	}
    }

    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	int n = Integer.parseInt(s[0]);
	int k = Integer.parseInt(s[1]);
	String p[] = br.readLine().split(" ");
	String c[] = br.readLine().split(" ");
	kn po[] = new kn[n];
	int a = 0, b = 0;
	for(int i = 0;i<n;i++){
	    a = Integer.parseInt(p[i]);
	    b = Integer.parseInt(c[i]);
	    po[i] = new kn(a,b,i,0);
	}
	Arrays.sort(po,(x,y)->{return x.p-y.p;});
	int ans[] = new int[n];
	int ac = 0;
	for(int i = 0; i<n;i++){
	    ac+=po[i].c;
	    ans[i] = ac;
	    if(i<=k){
		po[i].ans = ans[i];
		//		out.print(ans[i]+" ");
	    }else{
		po[i].ans = (ans[i]-ans[i-k-1]);
		//out.println((ans[i]-ans[i-k-1])+" ");
	    }
	}
	Arrays.sort(po,(x,y)->{return x.i-y.i;});
	for(int i = 0; i<n;i++){
	    out.print(po[i].ans+" ");
	}
	out.close();
    }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Main{
    public static class kn{
	int p,c,i;
	long ans;
	kn(int p, int c,int i, long ans){
	    this.p = p;
	    this.c = c;
	    this.i = i;
	    this.ans = ans;
	}
    }

    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	int n = Integer.parseInt(s[0]);
	int k = Integer.parseInt(s[1]);
	String p[] = br.readLine().split(" ");
	String c[] = br.readLine().split(" ");
	kn po[] = new kn[n];
	int a = 0, b = 0;
	for(int i = 0;i<n;i++){
	    a = Integer.parseInt(p[i]);
	    b = Integer.parseInt(c[i]);
	    po[i] = new kn(a,b,i,0);
	}
	Arrays.sort(po,(x,y)->{return x.p-y.p;});
	int ans[] = new int[n];
	long ac = 0;
	PriorityQueue<Integer> sum = new PriorityQueue<Integer>();
	for(int i = 0; i<n;i++){
	    if(i<=k){
		ac+=po[i].c;
		sum.add(po[i].c);
		po[i].ans = ac;
	    }else{
		ac-=sum.poll();;
		ac+=po[i].c;
		po[i].ans = ac;
		po[i].ans = (ac);
		sum.add(po[i].c);
	    }
	}
	Arrays.sort(po,(x,y)->{return x.i-y.i;});
	for(int i = 0; i<n;i++){
	    out.print(po[i].ans+" ");
	}
	out.close();
    }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.TreeSet;

public class Main{
    public static class kn{
	int p,c,i,ans;
	kn(int p, int c,int i, int ans){
	    this.p = p;
	    this.c = c;
	    this.i = i;
	    this.ans = ans;
	}
    }

    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	int n = Integer.parseInt(s[0]);
	int k = Integer.parseInt(s[1]);
	String p[] = br.readLine().split(" ");
	String c[] = br.readLine().split(" ");
	kn po[] = new kn[n];
	int a = 0, b = 0;
	for(int i = 0;i<n;i++){
	    a = Integer.parseInt(p[i]);
	    b = Integer.parseInt(c[i]);
	    po[i] = new kn(a,b,i,0);
	}
	Arrays.sort(po,(x,y)->{return x.p-y.p;});
	int ans[] = new int[n];
	int ac = 0;
	TreeSet<Integer> sum = new TreeSet<Integer>();
	for(int i = 0; i<n;i++){
	    if(i<=k){
		ac+=po[i].c;
		sum.add(po[i].c);
		po[i].ans = ac;
	    }else{
		ac-=sum.pollFirst();;
		ac+=po[i].c;
		po[i].ans = ac;
		po[i].ans = (ac);
		sum.add(po[i].c);
	    }
	}
	Arrays.sort(po,(x,y)->{return x.i-y.i;});
	for(int i = 0; i<n;i++){
	    out.print(po[i].ans+" ");
	}
	out.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author programajor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Container container = new Container(k);
            Knight[] knights = new Knight[n];
            for (int i = 0; i < n; i++) {
                knights[i] = new Knight(i, in.nextInt());
            }
            for (int i = 0; i < n; i++) {
                knights[i].coins = in.nextInt();
                knights[i].resultCoins = knights[i].coins;
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.power < o1.power ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                knight.resultCoins += container.getSum();
                container.add(knight.coins);
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.index < o1.index ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                out.print(knight.resultCoins + " ");
            }
        }

        class Knight {
            int index;
            int power;
            int coins;
            int resultCoins;

            Knight(int index, int power) {
                this.index = index;
                this.power = power;
            }

        }

        class Container {
            private final int k;
            private PriorityQueue<Integer> heap;

            Container(int k) {
                this.k = k;
                this.heap = new PriorityQueue<>();
            }

            void add(int coins) {
                if (heap.size() == k) {
                    heap.poll();
                }
                heap.add(coins);
            }

            int getSum() {
                int sum = 0;
                for (int num : heap) {
                    sum += num;
                }
                return sum;
            }

        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author programajor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Container container = new Container(k);
            Knight[] knights = new Knight[n];
            for (int i = 0; i < n; i++) {
                knights[i] = new Knight(i, in.nextInt());
            }
            for (int i = 0; i < n; i++) {
                knights[i].coins = in.nextInt();
                knights[i].resultCoins = knights[i].coins;
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.power < o1.power ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                knight.resultCoins += container.getSum();
                container.add(knight.coins);
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.index < o1.index ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                out.print(knight.resultCoins + " ");
            }
        }

        class Knight {
            int index;
            int power;
            int coins;
            int resultCoins;

            Knight(int index, int power) {
                this.index = index;
                this.power = power;
            }

        }

        class Container {
            private final int k;
            private PriorityQueue<Integer> heap;

            Container(int k) {
                this.k = k;
                this.heap = new PriorityQueue<>();
            }

            void add(int coins) {
                heap.add(coins);
                if (heap.size() > k) {
                    heap.poll();
                }
            }

            int getSum() {
                int sum = 0;
                for (int num : heap) {
                    sum += num;
                }
                return sum;
            }

        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author programajor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Container container = new Container(k);
            Knight[] knights = new Knight[n];
            for (int i = 0; i < n; i++) {
                knights[i] = new Knight(i, in.nextInt());
            }
            for (int i = 0; i < n; i++) {
                knights[i].coins = in.nextInt();
                knights[i].resultCoins = knights[i].coins;
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.power < o1.power ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                knight.resultCoins += container.getSum();
                container.add(knight.coins);
            }

            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o2.index < o1.index ? 1 : -1;
                }
            });

            for (Knight knight : knights) {
                out.print(knight.resultCoins + " ");
            }
        }

        class Knight {
            int index;
            int power;
            int coins;
            long resultCoins;

            Knight(int index, int power) {
                this.index = index;
                this.power = power;
            }

        }

        class Container {
            private final int k;
            private PriorityQueue<Long> heap;

            Container(int k) {
                this.k = k;
                this.heap = new PriorityQueue<>();
            }

            void add(long coins) {
                heap.add(coins);
                if (heap.size() > k) {
                    heap.poll();
                }
            }

            long getSum() {
                long sum = 0;
                for (long num : heap) {
                    sum += num;
                }
                return sum;
            }

        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author DY
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BKnightsOfAPolygonalTable solver = new BKnightsOfAPolygonalTable();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKnightsOfAPolygonalTable {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            Knight[] knights = new Knight[n];
            for (int i = 0; i < n; ++i) knights[i] = new Knight(i);
            for (int i = 0; i < n; ++i) knights[i].power = in.readInt();
            for (int i = 0; i < n; ++i) knights[i].coins = in.readInt();
            if (k == 0) {
                for (int i = 0; i < n; ++i) out.print(knights[i].coins + (i < n - 1 ? " " : "\n"));
                return;
            }
            Arrays.sort(knights, new Comparator<Knight>() {

                public int compare(Knight o1, Knight o2) {
                    return o1.power - o2.power;
                }
            });
            PriorityQueue<Integer> heap = new PriorityQueue<>();
            long[] max = new long[n];
            long acc = 0;
            for (int i = 0; i < n; ++i) {
                Knight cur = knights[i];
                max[cur.index] = acc + cur.coins;
                if (heap.size() < k) {
                    heap.add(cur.coins);
                    acc += cur.coins;
                } else if (heap.peek() < cur.coins) {
                    acc -= heap.peek();
                    acc += cur.coins;
                    heap.poll();
                    heap.add(cur.coins);
                }
            }
            for (int i = 0; i < n; ++i) out.print(max[i] + (i < n - 1 ? " " : "\n"));
        }

        class Knight {
            int power;
            int coins;
            int index;

            public Knight(int index) {
                this.index = index;
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}