//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;

        while (x > 0) {
            r = sc.nextInt();
            if (r > y) {
                continue;
            } else  {
                sum += r;
                s++;

            }
            x--;
        }
        System.out.println(s);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class juicer
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        OutputStream writer = new BufferedOutputStream(System.out);
        String[] info = reader.readLine().split(" ");
        int oranges = Integer.parseInt(info[0]);
        int maxSize = Integer.parseInt(info[1]);
        int dWaste = Integer.parseInt(info[2]);
        info = reader.readLine().split(" ");
        int total = 0;
        int count = 0;

        int[] orange = new int[oranges];
        for (int i = 0; i < oranges; i++)
        {
            orange[i] = Integer.parseInt(info[i]);
            if (orange[i] <= maxSize)
            {
                total += orange[i];
                if (total > dWaste)
                {
                    count++;
                    total = 0;
                }
            }
        }
        writer.write(count);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class juicer
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] info = reader.readLine().split(" ");
        int oranges = Integer.parseInt(info[0]);
        int maxSize = Integer.parseInt(info[1]);
        int dWaste = Integer.parseInt(info[2]);
        info = reader.readLine().split(" ");
        int total = 0;
        int count = 0;

        int[] orange = new int[oranges];
        for (int i = 0; i < oranges; i++)
        {
            orange[i] = Integer.parseInt(info[i]);
            if (orange[i] <= maxSize)
            {
                total += orange[i];
                if (total > dWaste)
                {
                    count++;
                    total = 0;
                }
            }
        }
        writer.write(count + "\n");
        reader.close();
        writer.close();
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class juicer
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] info = reader.readLine().split(" ");
        int oranges = Integer.parseInt(info[0]);
        int maxSize = Integer.parseInt(info[1]);
        int dWaste = Integer.parseInt(info[2]);
        info = reader.readLine().split(" ");
        int total = 0;
        int count = 0;

        int[] orange = new int[oranges];
        for (int i = 0; i < oranges; i++)
        {
            orange[i] = Integer.parseInt(info[i]);
            if (orange[i] <= maxSize)
            {
                total += orange[i];
                if (total > dWaste)
                {
                    count++;
                    total = 0;
                }
            }
        }
        System.out.println(count);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class juicer
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] info = reader.readLine().split(" ");
        int oranges = Integer.parseInt(info[0]);
        int maxSize = Integer.parseInt(info[1]);
        int dWaste = Integer.parseInt(info[2]);
        info = reader.readLine().split(" ");
        int total = 0;
        int count = 0;

        int[] orange = new int[oranges];
        for (int i = 0; i < oranges; i++)
        {
            orange[i] = Integer.parseInt(info[i]);
            if (orange[i] <= maxSize)
            {
                total += orange[i];
                if (total > dWaste) count++;
            }
        }
        System.out.println(count);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class juicer
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] info = reader.readLine().split(" ");
        int oranges = Integer.parseInt(info[0]);
        int maxSize = Integer.parseInt(info[1]);
        int dWaste = Integer.parseInt(info[2]);
        info = reader.readLine().split(" ");
        int total = 0;
        int count = 0;

        int[] orange = new int[oranges];
        for (int i = 0; i < oranges; i++)
        {
            orange[i] = Integer.parseInt(info[i]);
            if (orange[i] <= maxSize)
                total += orange[i];
            if (total > dWaste) count++;
        }
        System.out.println(count);
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b = sc.nextInt();
		int d = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++)
			arr[i] = sc.nextInt();
		long sum = 0;
		int c = 0;
		for(int i=0;i<n;i++){
			if (arr[i] > b)
				continue;
			sum+=arr[i];
			if (sum > d){
				sum = 0;
				c++;
			}
		}
		System.out.println(c);
	}
}


import java.util.Scanner;

public class CF709_D2_A {

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

        long sum = 0;
        for (int i=0;i<n;i++){
            int x = sc.nextInt();
            if (x <= b)
                sum += x;
        }
        System.out.println((long) Math.ceil(sum/d));
    }
}


import java.util.Scanner;

public class CF709_D2_A {

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

        long sum = 0;
        for (int i=0;i<n;i++){
            int x = sc.nextInt();
            if (x <= b)
                sum += x;
        }
        //System.out.println(sum +" % " + d +" = "+sum%d);
        System.out.println(sum%d == 0 && sum!= 0?(long) Math.ceil(sum/d)-1:(long) Math.ceil(sum/d));
    }
}


import java.util.Scanner;

public class CF709_D2_A {

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

        long sum = 0;
        int c = 0;
        for (int i=0;i<n;i++){
            int x = sc.nextInt();
            if (x <= b)
                sum += x;
            if (sum > d){
                sum = 0;
                c++;
            }
        }
        //System.out.println(sum +" % " + d +" = "+sum%d);
        System.out.println(c);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(read);
        int n,b,c=0,e=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            if(A[i]<b)
            {
                e++;
                if(e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n,b,c=0,e=0,d;
        n=sc.nextInt();
        b=sc.nextInt();
        d=sc.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=sc.nextInt();
            if(A[i]<=b)
            {
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        int n,b,d,x=0,y=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=Integer.parseInt(in.readLine());
            if(A[i]<b)
            {
                if(y+A[i])<=d)
                x+=A[i];
                else
                {
                    x=0;
                    y++;
                }
            }
        }
        System.out.println(y);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        int n,b,d,x=0,y=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=Integer.parseInt(in.readLine());
            if(A[i]<b)
            {
                if(y+A[i])<d)
                x+=A[i];
                else
                {
                    x=0;
                    y++;
                }
            }
        }
        System.out.println(y);
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n,b,c=0,e=0,d;
        n=sc.nextInt();
        b=sc.nextInt();
        d=sc.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=sc.nextInt();
            if(A[i]<=b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(read);
        int n,b,c=0,e=0,d;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            if(A[i]<b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
         Scanner sc=new Scanner(System.in);
        int n,b,c=0,e=0,d;
        n=sc.nextInt();
        b=sc.nextInt();
        d=sc.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=sc.nextInt();
            if(A[i]<=b)
            {
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(read);
        int n,b,c=0,e=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            if(A[i]<b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(read);
        int n,b,c=0,e=0,d;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            if(A[i]<b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n,b,c=0,e=0,d;
        n=sc.nextInt();
        b=sc.nextInt();
        d=sc.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=sc.nextInt();
            if(A[i]<b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        int n,b,d,x=0,y=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=Integer.parseInt(in.readLine());
            if(A[i]<b)
            {
                if(x+A[i])<d)
                x+=A[i];
                else
                {
                    x=A[i];
                    y++;
                }
            }
        }
    }
}


import java.io.*;
public class abc
{
    public static void main(String ar[])throws IOException
    {
        int n,b,d,x=0,y=0;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=Integer.parseInt(in.readLine());
            if(A[i]<b)
            {
                if(y+A[i])<d)
                x+=A[i];
                else
                {
                    x=0;
                    y++;
                }
            }
        }
    }
}


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

public class abc
{
    public static void main(String ar[])throws IOException
    {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(read);
        int n,b,c=0,e=0,d;
        n=Integer.parseInt(in.readLine());
        b=Integer.parseInt(in.readLine());
        d=Integer.parseInt(in.readLine());
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=Integer.parseInt(in.readLine());
            if(A[i]<b)
            {
                e++;
                if((e+A[i])<=d)
                {
                    e+=A[i];
                }
                else
                {
                    e=0;
                    c++;
                }
            }
        }
        System.out.println(c);
    }
}


import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
//            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange >= maxOrangeSize)
                continue;
            orangeSizes+= orange;

            if (orangeSizes > wasteLevel) {
                numberOfEmpty++;
                orangeSizes -=wasteLevel;
            }
        }
        return numberOfEmpty;
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
//            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange > maxOrangeSize)
                break;
            orangeSizes+= orange;

            if (orangeSizes >= wasteLevel) {
                numberOfEmpty++;
                orangeSizes -=wasteLevel;
            }
        }
        return numberOfEmpty;
    }
}


/**
 * @author: sherreea@amazon.com
 * Date: 2019-10-28
 */
package codeforces;

import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
//            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange >= maxOrangeSize)
                break;
            orangeSizes+= orange;

            if (orangeSizes >= wasteLevel) {
                numberOfEmpty++;
                orangeSizes -=wasteLevel;
            }
        }
        return numberOfEmpty;
    }
}


import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
//            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange >= maxOrangeSize)
                break;
            orangeSizes+= orange;

            if (orangeSizes >= wasteLevel) {
                numberOfEmpty++;
                orangeSizes -=wasteLevel;
            }
        }
        return numberOfEmpty;
    }
}


import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
//            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange >= maxOrangeSize)
                break;
            orangeSizes+= orange;

            if (orangeSizes >= wasteLevel) {
                numberOfEmpty++;
                orangeSizes -=wasteLevel;
            }
        }
        return numberOfEmpty;
    }
}


import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class SolutionTest implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new SolutionTest(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
//            in = new BufferedReader(new FileReader("src/codeforces/input.txt"));
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    // solution
    void solve() throws IOException {
        out.println(juicer709A());
    }

    private int juicer709A() throws IOException {
        int numberOfOranges = readInt();
        int maxOrangeSize = readInt();
        int wasteLevel = readInt();
        int numberOfEmpty = 0;
        int orangeSizes = 0;

        for (int i = 0; i < numberOfOranges; i++) {
            int orange = readInt();
            if (orange > maxOrangeSize)
                continue;
            orangeSizes += orange;

            if (orangeSizes > wasteLevel) {
                numberOfEmpty++;
                orangeSizes = 0;
            }
        }
        return numberOfEmpty;
    }
}


// package com.company;

import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    static class FastReader {
        private BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        try {
            FastReader sc = new FastReader();
            long n = sc.nextInt();
            long b = sc.nextInt();
            long d = sc.nextInt();
            long squeeze=0;
            long count=0;
            for(int i=0;i<n;i++){
                int a = sc.nextInt();
                if(a<=b){
                    squeeze+=a;
                    if(squeeze>10){
                        squeeze=0;
                        count+=1;
                    }
                }
                else{
                    i++;
                }
            }
            System.out.println(count);

        }
        catch (Exception e) {
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    static class FastReader {
        private BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        try {
            FastReader sc = new FastReader();
            long n = sc.nextInt();
            long b = sc.nextInt();
            long d = sc.nextInt();
            long squeeze=0;
            long count=0;
            for(int i=0;i<n;i++){
                int a = sc.nextInt();
                squeeze+=a<=b?a:0;
                    squeeze+=a;
                    if(squeeze>d){
                        squeeze=0;
                        count+=1;
                    }
            }
            System.out.println(count);

        }
        catch (Exception e) {
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    static class FastReader {
        private BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        try {
            FastReader sc = new FastReader();
            long n = sc.nextInt();
            long b = sc.nextInt();
            long d = sc.nextInt();
            long squeeze=0;
            long count=0;
            for(int i=0;i<n;i++){
                int a = sc.nextInt();
                squeeze+=a<=b?a:0;
                    squeeze+=a;
                    if(squeeze>10){
                        squeeze=0;
                        count+=1;
                    }
            }
            System.out.println(count);

        }
        catch (Exception e) {
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    static class FastReader {
        private BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        try {
            FastReader sc = new FastReader();
            long n = sc.nextInt();
            long b = sc.nextInt();
            long d = sc.nextInt();
            long squeeze=0;
            long count=0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                squeeze += a<=b?a:0;
                if ((squeeze) > d) {
                    squeeze = 0;
                    count++;
                }
            }
            System.out.println(count);

        }
        catch (Exception e) {
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    static class FastReader {
        private BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        try {
            FastReader sc = new FastReader();
            int n = sc.nextInt();
            int b = sc.nextInt();
            int d = sc.nextInt();
            int squeeze=0;
            int count=0;
            for(int i=0;i<n;i++){
                int a = sc.nextInt();
                if(a<=b){
                    squeeze+=a;
                    if(squeeze>10){
                        squeeze=0;
                        count+=1;
                    }
                }
                else{
                    i++;
                }
            }
            System.out.println(count);

        }
        catch (Exception e) {
        }
    }
}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;

        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;
            }
        }

        if (t%d != 0) {
            t = t/d;
        }else if (t/d == 0) {
            t =0;
        }else
            t = t/d - 1;

        System.out.println(t);

    }

}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;

        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;
            }
        }

        if (t%d != 0) {
            t = t/d;
        }else
            t = t/d - 1;

        System.out.println(t);

    }

}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;

        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;
            }
        }

        if (t != d) {
            t = t/d;
        }else
            t =0;

        System.out.println(t);

    }

}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;

        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;
            }
        }

        t = t/d;

        System.out.println(t);

    }

}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;
        int f = 0;
        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;

            }
            if (t > d) {
                t =0;
                f++;
            }
        }

        System.out.println(f);

    }

}


import java.util.Scanner;

public class Comp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int b = input.nextInt();
        int d = input.nextInt();

        int t = 0;
        int s;

        for (int i = 0; i < n; i++) {
            s = input.nextInt();
            if (s <= b) {
                t += s;
            }
        }
        s = 0;
        while ( t > d){
            s++;
            t -= d;
        }

        System.out.println(s);

    }

}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
struct node
{
    ll p;
    ll c;
    int index;
    int sum;
} a[maxn];
bool cmp(node x, node y)
{
    return x.p > y.p;
}
bool cmp2(node x, node y)
{
    return x.c > y.c;
}
bool cmp3(node x, node y)
{
    return x.index < y.index;
}
int main()
{
    ll sum;
    int n,k;
    int Sc[maxn];
    ll ans[maxn];
    ios::sync_with_stdio(false);
    while(cin >> n >> k)
    {
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i].p;
            a[i].index = i;
        }

        for(int i = 1; i <= n; i++) cin >> a[i].c;
        int pp=0;
        sum=0;
        sort(a+1,a+1+n,cmp);
        for(int i=pp+1; i<=n; i++)
        {

            sort(a+i+1,a+n+1,cmp2);
            sum=0;
            for(int j=0; j<=k; j++)
            {
                sum=sum+a[i+j].c;
            }
            a[i].sum=sum;
            pp=pp+1;
            sort(a+i+1,a+n+1,cmp);
        }
        sort(a+1, a+1+n, cmp3);
        for(int i=1; i<n; i++)
            cout<<a[i].sum<<" ";
            cout << a[n].sum<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector <pair<ll, ll> > v(n);
    vector <ll> mv;
    unordered_map <ll, ll> mp;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin >> x;
        mv.push_back(x);
        v[i].first = x;
    }
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin >> x;
        v[i].second = x;
    }
    sort(v.rbegin(), v.rend());
    vector <pair<ll, ll> > :: iterator it, ip;
    for(it=v.begin(); it!=v.end(); it++)
    {
        ll sum=it->second;
        ip=it+1;
        ll cnt=0;
        while(cnt<k && ip!=v.end())
        {
            sum+=ip->second;
            cnt++;
            ip++;
        }
        mp[it->first]=sum;
    }
    for(auto i:mv)
        cout << mp[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct knight
{
    ll power, coin, id;
};
bool cmp(struct knight k1, struct knight k2)
{
    return k1.power<k2.power;
}
int main()
{
    ll n, k;
    cin >> n >> k;
    knight a[n];
    for(ll i=0; i<n; i++)
        cin >> a[i].power;
    for(ll i=0; i<n; i++)
    {
        cin >> a[i].coin;
        a[i].id=i;
    }
    ll b[n];
    sort(a, a+n, cmp);
    for(ll i=0; i<n; i++)
    {
        ll x=0, sum=0, m=LONG_MAX;
        for(ll j=i-1; j>=0; j--)
        {
            if(x==k)
                break;
            x++;
            m=min(m, a[j].coin);
            sum+=a[j].coin;
        }
        if(x<=k)
            sum+=a[i].coin;
        else if(m!=LONG_MAX && m>a[i].coin)
            sum=sum-m+a[i].coin;
        ll p=a[i].id;
        b[p]=sum;
     }
     for(ll i=0; i<n; i++)
        cout << b[i] << " ";
     return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct knight
{
    ll power;
    ll coin;
    ll id;
};
bool cmp(struct knight k1, struct  knight k2)
{
    return k1.coin>k2.coin;
}
int main()
{
   ll n, k, x;
   cin >> n >> k;
   ll a[n];
   memset(a, 0, sizeof(a));
   vector <knight> v(n);
   for(ll i=0; i<n; i++)
   {
       cin >> x;
       v[i].power=x;
       v[i].id=i;
   }
   for(ll i=0; i<n; i++)
   {
       cin >> x;
       v[i].coin=x;
   }
   sort(v.begin(), v.end(), cmp);
   ll sum=0;
   vector <knight> :: iterator it, ip;
   for(it=v.begin(); it!=v.end(); it++)
   {
       ll cx=it->coin, cy=0;
       for(ip=v.begin(); ip!=v.end() && cy<k; ip++)
       {
           if(ip->power<=it->power && ip!=it)
           {
               cx+=ip->coin;
               cy++;
           }
       }
       a[it->id]=cx;
   }
   for(ll i=0; i<n; i++)
   {
       cout << a[i] << " ";
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector <pair<ll, ll> > v(n);
    vector <ll> mv;
    unordered_map <ll, ll> mp;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin >> x;
        mv.push_back(x);
        v[i].first = x;
    }
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin >> x;
        v[i].second = x;
    }
    sort(v.rbegin(), v.rend());
    vector <pair<ll, ll> > :: iterator it, ip;
    for(it=v.begin(); it!=v.end(); it++)
    {
        ll sum=it->second;
        ip=it+1;
        ll cnt=0;
        priority_queue <ll> pq;
        while(ip!=v.end())
        {
            pq.push(ip->second);
            ip++;
        }
        while(!pq.empty() && cnt<k)
        {
            sum+=pq.top();
            pq.pop();
            cnt++;
        }
        mp[it->first]=sum;
    }
    for(auto i:mv)
        cout << mp[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct knight
{
    ll power, coin, id;
};
bool cmp(struct knight k1, struct knight k2)
{
    return k1.power<k2.power;
}
int main()
{
    ll n, k;
    cin >> n >> k;
    knight a[n];
    for(ll i=0; i<n; i++)
        cin >> a[i].power;
    for(ll i=0; i<n; i++)
    {
        cin >> a[i].coin;
        a[i].id=i;
    }
    ll b[n];
    sort(a, a+n, cmp);
    priority_queue <ll> pq;
    for(ll i=0; i<n; i++)
    {
        vector <ll> v;
        ll x=0, sum=a[i].coin;

        while(!pq.empty())
        {
            if(x==k)break;
            ll y=pq.top();
            sum+=y;
            v.push_back(y);
            pq.pop();
            x++;
        }
        pq.push(a[i].coin);
        for(auto it:v)
            pq.push(it);
        ll p=a[i].id;
        b[p]=sum;
     }
     for(ll i=0; i<n; i++)
        cout << b[i] << " ";
     return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct knight
{
    ll power;
    ll coin;
    ll id;
};
bool cmp(struct knight k1, struct  knight k2)
{
    return k1.power>k2.power;
}
int main()
{
   ll n, k, x;
   cin >> n >> k;
   ll a[n];
   memset(a, 0, sizeof(a));
   vector <knight> v(n);
   for(ll i=0; i<n; i++)
   {
       cin >> x;
       v[i].power=x;
       v[i].id=i;
   }
   for(ll i=0; i<n; i++)
   {
       cin >> x;
       v[i].coin=x;
   }
   sort(v.begin(), v.end(), cmp);
   ll sum=0;
   vector <knight> :: iterator it, ip;
   for(it=v.begin(); it!=v.end(); it++)
   {
       ll cx=0, cy=0;
       for(ip=it; ip!=v.end() && cy<=k; ip++, cy++)
       {
           cx+=ip->coin;
       }
       a[it->id]=cx;
   }
   for(ll i=0; i<n; i++)
   {
       cout << a[i] << " ";
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,k;
cin>>n>>k;
map<int,int> mp;
map<int,int> p;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    ll ans=p[i];
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,k;
cin>>n>>k;
map<ll,ll> mp;
map<ll,ll> p;
vector<pair<ll,ll> > v(n);
for(ll i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(ll i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(ll i=1;i<=n;i++){
    ll temp=mp[i];
    ll l=k;
    ll ans=p[i];
    ll j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
int n,k;
cin>>n>>k;
map<int,int> mp;
vector<pair<int,int> > v(n+1);
for(int i=1;i<=n;i++){
        cin>>v[i].second;
          mp[i]=v[i].second;
}
for(int i=1;i<=n;i++){
        cin>>v[i].first;

}

sort(v.rbegin(),v.rend());
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    ll ans=v[i].first;
    int j=1;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,k;
cin>>n>>k;
vector<pair<ll,ll> >v(n);
map<ll,ll> mp;
ll arr[n];
for(ll i=0;i<n;i++)
{
    cin>>v[i].first;
    mp[v[i].first]=i;
}
for(ll i=0;i<n;i++)
{
    cin>>v[i].second;
}
sort(v.begin(),v.end());

multiset<int> s;
ll cur=0;
for(ll i=0;i<n;i++)
{
    if(s.size()>=k+1)
    {
       auto val=*s.begin();
       cur-=val;
       s.erase(s.lower_bound(val));
    }

    s.insert(v[i].second);
    cur+=v[i].second;
    arr[mp[v[i].first]]=cur;
}
for(int i=0;i<n;i++)
{
	cout<<arr[i]<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
int n,k;
cin>>n>>k;
map<int,int> mp;
map<int,int> p;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    ll ans=p[i];
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,k;
cin>>n>>k;
map<int,int> mp;
map<int,int> p;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    ll ans=p[i];
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,k;
cin>>n>>k;
map<int,int> mp;
map<int,int> p;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    ll ans=p[i];
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
int n,k;
cin>>n>>k;
map<int,int> mp;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;

}

sort(v.rbegin(),v.rend());

for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    int ans=v[n-i].first;
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
int n,k;
cin>>n>>k;
map<int,int> mp;
map<int,int> p;
vector<pair<int,int> > v(n);
for(int i=1;i<=n;i++){
        cin>>v[i-1].second;
          mp[i]=v[i-1].second;
}
for(int i=0;i<n;i++){
        cin>>v[i].first;
        p[i+1]=v[i].first;

}

sort(v.rbegin(),v.rend());
//for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
for(int i=1;i<=n;i++){
    int temp=mp[i];
    int l=k;
    int ans=p[i];
    int j=0;
    while(l>0)
    {
        if(j==n)break;
        if(v[j].second<temp)
        {
            ans+=v[j].first;
            l--;
        }
        j++;
    }
    cout<<ans<<" ";
}

}


#include<bits/stdc++.h>
#include<set>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
int main()
{     int n,k;
      cin>>n>>k;
      set<ll>p;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      ll sum[100005];

      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
	  }
	 auto it=p.begin();
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       sum[k+1]-=*it;
	      // cout<<*p.begin()<<endl;
	        p.erase(*it);
	       sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
ll sum[20];
multiset<ll>p;
multiset<ll>::iterator it;

int main()
{     int n,k;
      cin>>n>>k;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      if(k==0)
      {  for(int i=1;i<=n;i++)
          {  cout<<s[i].b <<" ";
		  }
		  printf("\n");
		  return 0;
	  }
      sort(s+1,s+n+1,cmp);
      memset(sum,0,sizeof(sum));
      if(k>=n-1)
      {   k=n-1;
	  }
      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
      }
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       if(*p.begin()==s[i].b )
	       {   it=p.begin();
	            it++;
		       sum[k+1]-=*it;
		      // cout<<*it<<endl;
	          p.erase(it);
	           sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
		   }
	        else
	        {   it=p.begin();
			    sum[k+1]-=*it;

	             p.erase(it);
	             sum[k+1]+=s[i].b;
	             s[i].b =sum[k+1];
			}
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
ll sum[20];
set<ll>p;
set<ll>::iterator it;
int main()
{     int n,k;
      cin>>n>>k;

      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      memset(sum,0,sizeof(sum));
      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
     }
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       if(*p.begin()==s[i].b )
	       {   it=p.begin();
	            it++;
		       sum[k+1]-=*it;
	          p.erase(it);
	           sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	       it--;
		   }
	        else
	        {   sum[k+1]-=*p.begin();
	             p.erase(*p.begin());
	             sum[k+1]+=s[i].b;
	             s[i].b =sum[k+1];
			}
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
ll sum[20];
set<ll>p;
set<ll>::iterator it;
int main()
{     int n,k;
      cin>>n>>k;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      if(k==0)
      {  for(int i=1;i<=n;i++)
          {  cout<<s[i].b <<" ";
		  }
		  printf("\n");
		  return 0;
	  }
      sort(s+1,s+n+1,cmp);
      memset(sum,0,sizeof(sum));
      if(k>=n-1)
      {   k=n-1;
	  }
      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
      }
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       if(*p.begin()==s[i].b )
	       {   it=p.begin();
	            it++;
		       sum[k+1]-=*it;
	          p.erase(it);
	           sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
		   }
	        else
	        {   it=p.begin();
			    sum[k+1]-=*it;
	             p.erase(it);
	             sum[k+1]+=s[i].b;
	             s[i].b =sum[k+1];
			}
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
ll sum[20];
int main()
{     int n,k;
      cin>>n>>k;
      set<ll>p;
      set<ll>::iterator it;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      memset(sum,0,sizeof(sum));
      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
     }
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       if(*p.begin()==s[i].b )
	       {   it=p.begin();
	            it++;
		       sum[k+1]-=*it;
	          p.erase(it);
	           sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	       it--;
		   }
	        else
	        {   sum[k+1]-=*p.begin();
	             p.erase(*p.begin());
	             sum[k+1]+=s[i].b;
	             s[i].b =sum[k+1];
			}
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
int main()
{     int n,k;
      cin>>n>>k;
      set<ll>p;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      ll sum[100005];

      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
	  }

	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       sum[k+1]-=*p.begin();

	        p.erase(*p.begin());
	       sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
int main()
{     int n,k;
      cin>>n>>k;
      set<ll>p;
      set<ll>::iterator it;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      ll sum[100005];
      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
     }
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       if(*p.begin()==s[i].b )
	       {   it=p.begin();
	            it++;
		       sum[k+1]-=*it;
	          p.erase(it);
	           sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	       it--;
		   }
	        else
	        {   sum[k+1]-=*p.begin();
	             p.erase(*p.begin());
	             sum[k+1]+=s[i].b;
	             s[i].b =sum[k+1];
			}
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include<bits/stdc++.h>
#include<set>
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
struct node
{    ll a,b,id;
}s[100005];
bool cmp(node x,node y)
{   return x.a <y.a ;
}
bool cmp1(node x,node y)
{  return x.id <y.id;
}
int main()
{     int n,k;
      cin>>n>>k;
      set<ll>p;
      for(int i=1;i<=n;i++ )
      {  cin>>s[i].a ;s[i].id =i;
	  }
      for(int i=1;i<=n;i++)
      cin>>s[i].b ;
      sort(s+1,s+n+1,cmp);
      ll sum[100005];

      for(int i=1;i<=k+1;i++)
      {    sum[i]=sum[i-1]+s[i].b ;
          p.insert(s[i].b);
          s[i].b =sum[i];
	  }
	//  auto it=p.begin();
	  for(int i=k+2;i<=n;i++)
	  {    p.insert(s[i].b);
	       sum[k+1]-=*p.begin();
	      // cout<<*p.begin()<<endl;
	        p.erase(*p.begin());
	       sum[k+1]+=s[i].b ;
	       s[i].b=sum[k+1];
	  }
	  sort(s+1,s+n+1,cmp1);
	  for(int i=1;i<=n;i++)
	  {  printf("%lld%c",s[i].b,i==n?'\n':' ');
	  }
	  return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int n, k, sum = 0, j;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first << " ";
        }
    } else {
        sort(p.begin(), p.end());
        vector <bool> used(n, false);
        priority_queue < int, vector<int>, greater<int> > q;
        for (int i = 0; i < n; ++i) {
            if (i > 0) {
                j = i - 1;
            } else {
                j = 0;
            }
            if (p[j].first < p[i].first) {
                if (q.size() < k && !used[j]) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                    used[j] = true;
                } else if (!q.empty() && p[j].second.first > q.top() && !used[j]) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    used[j] = true;
                    sum += p[j].second.first;
                }
            }

            res[p[i].second.second] = sum + p[i].second.first;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    int n, k, sum;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());

        for (int i = 0; i < n; ++i) {
            sum = 0;
            priority_queue < int, vector<int>, greater<int> > q;
            for (int j = 0; p[j].first < p[i].first; ++j) {
                if (q.size() < k) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                } else if (!q.empty() && p[j].second.first > q.top()) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                }
            }

            sum += p[i].second.first;
            res[p[i].second.second] = sum;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int n, k, sum = 0, j;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());
        vector <bool> used(n, false);
        priority_queue < int, vector<int>, greater<int> > q;
        for (int i = 0; i < n; ++i) {
            if (i > 0) {
                j = i - 1;
            } else {
                j = 0;
            }
            if (p[j].first < p[i].first) {
                if (q.size() < k && !used[j]) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                    used[j] = true;
                } else if (!q.empty() && p[j].second.first > q.top() && !used[j]) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    used[j] = true;
                    sum += p[j].second.first;
                }
            }

            res[p[i].second.second] = sum + p[i].second.first;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());
        // for (int i = 0; i < n; ++i) {
        //     cout << p[i].first << " ";
        // }
        // cout << "\n";
        vector <bool> used(n, false);
        priority_queue < int, vector<int>, greater<int> > q;
        for (int i = 0; i < n; ++i) {
            //sum = 0;

            for (int j = 0; p[j].first < p[i].first; ++j) {
                if (q.size() < k && !used[j]) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                    used[j] = true;
                } else if (!q.empty() && p[j].second.first > q.top() && !used[j]) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    used[j] = true;
                    sum += p[j].second.first;
                }
            }

            sum += p[i].second.first;
            res[p[i].second.second] = sum;
            sum -= p[i].second.first;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());
        priority_queue < int, vector<int>, greater<int> > q;
        for (int i = 0; i < n; ++i) {
            //sum = 0;

            for (int j = 0; p[j].first < p[i].first; ++j) {
                if (q.size() < k) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                } else if (!q.empty() && p[j].second.first > q.top()) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                }
            }

            sum += p[i].second.first;
            res[p[i].second.second] = sum;
            sum -= p[i].second.first;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int n, k, sum = 0;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<int> res(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());
        vector <bool> used(n, false);
        priority_queue < int, vector<int>, greater<int> > q;
        for (int i = 0; i < n; ++i) {

            for (int j = 0; p[j].first < p[i].first; ++j) {
                if (q.size() < k && !used[j]) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                    used[j] = true;
                } else if (!q.empty() && p[j].second.first > q.top() && !used[j]) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    used[j] = true;
                    sum += p[j].second.first;
                }
            }

            res[p[i].second.second] = sum + p[i].second.first;
        }

        for (int i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    long long n, k, sum = 0, j;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);
    std::vector<long long> res(n);

    for (long long i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (long long i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (long long i = 0; i < n; ++i) {
            cout << p[i].second.first << " ";
        }
    } else {
        sort(p.begin(), p.end());
        vector <bool> used(n, false);
        priority_queue < long long, vector<long long>, greater<long long> > q;
        for (long long i = 0; i < n; ++i) {
            if (i > 0) {
                j = i - 1;
            } else {
                j = 0;
            }
            if (p[j].first < p[i].first) {
                if (q.size() < k && !used[j]) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                    used[j] = true;
                } else if (!q.empty() && p[j].second.first > q.top() && !used[j]) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    used[j] = true;
                    sum += p[j].second.first;
                }
            }

            res[p[i].second.second] = sum + p[i].second.first;
        }

        for (long long i = 0; i < n; ++i) {
            cout << res[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main()
{
    int n, k, sum;
    cin >> n >> k;
    vector < pair<long long, pair<long long, long long > > > p(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first;
        p[i].second.second = i;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i].second.first;
    }

    if (k == 0) {
        for (int i = 0; i < n; ++i) {
            cout << p[i].second.first;
        }
    } else {
        sort(p.begin(), p.end());

        for (int i = 0; i < n; ++i) {
            sum = 0;
            priority_queue < int, vector<int>, greater<int> > q;
            for (int j = 0; j < i; ++j) {
                if (q.size() < k) {
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                } else if (!q.empty() && p[j].second.first > q.top()) {
                    sum -= q.top();
                    q.pop();
                    q.push(p[j].second.first);
                    sum += p[j].second.first;
                }
            }

            sum += p[i].second.first;
            cout << sum << " ";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    ++k;
    foo(i, n, 1, 1) {
        q.push(p[i].S.F);
        int t = k;
        priority_queue < int > y = q;
        while (k && !q.empty()) ans[p[i].S.S] += q.top(), q.pop(),--k;
        q = y;
        k = t;
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

#define int ll

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    foo(i, n, 1, 1) {
        if (i == n) {
            q.push(p[i].S.F);
            ans[p[i].S.S] = p[i].S.F;
            continue;
        }
        priority_queue < int > y = q;
        int t = k;
        while (k && !q.empty()) ans[p[i].S.S] += q.top(), q.pop(),--k;
        q = y;
        k = t;
        ans[p[i].S.S] += p[i].S.F;
        q.push(p[i].S.F);
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    fo(i, 1, n, 1) {
        ans[p[i].S.S] = p[i].S.F;
        if (i == n) break;
        int t = k;
        for (int j = i + 1; k && j <= n; ++j) {
            if (p[j].F < p[i].F) {
                ans[p[i].S.S] += p[j].S.F;
                --k;
            }
        }
        k = t;
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

#define int ll

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    fo(i, 1, n, 1) {
        if (i == 1) {
            ans[p[i].S.S] = p[i].S.F;
            continue;
        }
        ans[p[i].S.S] = ans[p[i - 1].S.S] - p[i - 1].S.F + p[i].S.F;
        if (k) {
            ans[p[i].S.S] += p[i + 1].S.F;
            --k;
        }
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

#define int ll

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q, qq;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    bool t = 0;
    foo(i, n, 1, 1) {
        if (!t) {
            if (i == n) {
                q.push(p[i].S.F);
                ans[p[i].S.S] = p[i].S.F;
                continue;
            }
            int tt = k;
            while (k && !q.empty()) ans[p[i].S.S] += q.top(), qq.push(q.top()), q.pop(),--k;
            k = tt;
            ans[p[i].S.S] += p[i].S.F;
            qq.push(p[i].S.F);
            t = 1;
        }
        else {
            int tt = k;
            while (k && !qq.empty()) ans[p[i].S.S] += qq.top(), q.push(qq.top()), qq.pop(),--k;
            k = tt;
            ans[p[i].S.S] += p[i].S.F;
            q.push(p[i].S.F);
            t = 0;
        }
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

#define int ll

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    foo(i, n, 1, 1) {
        if (i == n) {
            q.push(p[i].S.F);
            continue;
        }
        priority_queue < int > y = q;
        int t = k;
        while (k && !q.empty()) ans[p[i].S.S] += q.top(), q.pop(),--k;
        q = y;
        k = t;
        q.push(p[i].S.F);
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md l + ((r - l) >> 1)
#define all(x) x.begin(),x.end()
#define ll long long
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const ll INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);

#define int ll

int n, k;
ll ans[N];
pair < int, pair < int, int > > p[N];
inline bool cmp(pair < int, pair < int, int > > a, pair < int, pair < int, int > > b) {
    return a.F > b.F;
}
priority_queue < int > q;
main() {
    file("queue");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> p[i].F;
    fo(i, 1, n, 1) cin >> p[i].S.F, p[i].S.S = i;
    sort(p + 1, p + n + 1, & cmp);
    ++k;
    foo(i, n, 1, 1) {
        q.push(p[i].S.F);
        int t = k;
        priority_queue < int > y = q;
        while (k && !q.empty()) ans[p[i].S.S] += q.top(), q.pop(),--k;
        q = y;
        k = t;
    }
    fo(i, 1, n, 1) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, k, maxf = 0;
    cin >> n >> k;
    vector <long long> f(n);
    vector <long long> m(n);
    vector < pair <long long, long long> > p;
    for (long long i = 0; i < n; i++)
    {
        cin >> f[i];
        maxf = max(maxf, f[i]);
    }
    maxf++;
    for (long long i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (long long i = 0; i < n; i++)
    {
        p.push_back({f[i], m[i]});
    }
    sort(p.begin(), p.end());
    multiset <long long> money;
    long long cost = 0;
    vector <long long> ans(maxf, 0);
    for (long long i = 0; i < n; i++)
    {
        long long mon = p[i].second;
        long long fi = p[i].first;
        if (money.size() <= k)
        {
            cost += mon;
            money.insert(mon);
        }
        else if (mon > *money.begin())
        {
            cost -= *money.begin();
            cost += mon;
            money.erase(money.begin());
            money.insert(mon);
        }
        ans[fi] = cost;
    }
    for (long long i = 0; i < n; i++)
    {
        //cout << '!' << f[i] << " " << maxf << endl;
        cout << ans[f[i]] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, k, maxf = 0;
    cin >> n >> k;
    vector <long long> f(n);
    vector <long long> m(n);
    vector < pair <pair <long long, long long>, long long>  > p(n);
    for (long long i = 0; i < n; i++)
    {
        cin >> f[i];
        maxf = max(maxf, f[i]);
    }
    for (long long i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (long long i = 0; i < n; i++)
        p[i] = {{f[i], m[i]}, i};
    sort(p.begin(), p.end());
    multiset <int> money;
    long long cost = 0;
    vector <long long> ans(n + 1, 0);
    for (long long i = 0; i < n; i++)
    {
        long long mon = p[i].first.second;
        long long fi = p[i].first.first;
        ans[p[i].second] = cost + mon;
        if (k > 0)
        {
            if (money.size() < k)
            {
                cost += mon;
                money.insert(mon);
            }
            else if (mon > *money.begin())
            {
                cost -= *money.begin();
                cost += mon;
                money.erase(money.begin());
                money.insert(mon);
            }
        }
    }
    for (long long i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, k, maxf = 0;
    cin >> n >> k;
    vector <long long> f(n);
    vector <long long> m(n);
    vector < pair <pair <long long, long long>, long long>  > p(n);
    for (long long i = 0; i < n; i++)
    {
        cin >> f[i];
        maxf = max(maxf, f[i]);
    }
    for (long long i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (long long i = 0; i < n; i++)
        p[i] = {{f[i], m[i]}, i};
    sort(p.begin(), p.end());
    multiset <int> money;
    long long cost = 0;
    vector <long long> ans(n + 1, 0);
    for (long long i = 0; i < n; i++)
    {
        long long mon = p[i].first.second;
        long long fi = p[i].first.first;
        ans[p[i].second] = cost + mon;
        if (money.size() < k)
        {
            cost += mon;
            money.insert(mon);
        }
        else if (mon > *money.begin())
        {
            cost -= *money.begin();
            cost += mon;
            money.erase(money.begin());
            money.insert(mon);
        }
    }
    for (long long i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, k, maxf = 0;
    cin >> n >> k;
    vector <long long> f(n);
    vector <long long> m(n);
    vector < pair <long long, long long> > p;
    for (long long i = 0; i < n; i++)
    {
        cin >> f[i];
        maxf = max(maxf, f[i]);
    }
    maxf++;
    for (long long i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (long long i = 0; i < n; i++)
        p.push_back({f[i], m[i]});
    sort(p.begin(), p.end());
    multiset <long long> money;
    long long cost = 0;
    vector <long long> ans(maxf + 1, 0);
    for (long long i = 0; i < n; i++)
    {
        long long mon = p[i].second;
        long long fi = p[i].first;
        ans[fi] = cost + mon;
        if (money.size() < k)
        {
            cost += mon;
            money.insert(mon);
        }
        else if (mon > *money.begin())
        {
            cost -= *money.begin();
            cost += mon;
            money.erase(money.begin());
            money.insert(mon);
        }
    }
    for (long long i = 0; i < n; i++)
    {
        //cout << '!' << f[i] << " " << maxf << endl;
        cout << ans[f[i]] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
    vector <pair <long long, long long> >money;
    vector <pair <long long, long long> >strong;
    vector <long long> used;
    vector <long long> ans;
int main(){
    long long n, k;
    cin >> n >> k;
    used.resize(n, 0);
    ans.resize(n);
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        strong.push_back({q, i});
    }
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        money.push_back({q, i});
    }
    sort(money.begin(), money.end());
    sort(strong.begin(), strong.end());
    for (long long i = strong.size() - 1; i >= 0; i--)
    {
        used[strong[i].second] = true;
        long long cnt = 0, cnt1 = 0;
        for (long long j = money.size() - 1; j >= 0; j--)
        {
            if (cnt1 == k)
                break;
            if (!used[money[j].second])
            {
                cnt += money[j].first;
                cnt1++;
            }
        }
        ans[strong[i].second] = cnt + money[strong[i].second].first;
    }
    for (long long i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, k, maxf = 0;
    cin >> n >> k;
    vector <long long> f(n);
    vector <long long> m(n);
    vector < pair <long long, long long> > p;
    for (long long i = 0; i < n; i++)
    {
        cin >> f[i];
        maxf = max(maxf, f[i]);
    }
    maxf++;
    for (long long i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (long long i = 0; i < n; i++)
    {
        p.push_back({f[i], m[i]});
    }
    sort(p.begin(), p.end());
    multiset <long long> money;
    long long cost = 0;
    vector <long long> ans(maxf, 0);
    for (long long i = 0; i < n; i++)
    {
        long long mon = p[i].second;
        long long fi = p[i].first;
        ans[fi] = cost + mon;
        if (money.size() < k)
        {
            cost += mon;
            money.insert(mon);
        }
        else if (mon > *money.begin())
        {
            cost -= *money.begin();
            cost += mon;
            money.erase(money.begin());
            money.insert(mon);
        }
    }
    for (long long i = 0; i < n; i++)
    {
        //cout << '!' << f[i] << " " << maxf << endl;
        cout << ans[f[i]] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
    vector <pair <long long, long long> >money;
    vector <pair <long long, long long> >strong;
    vector <long long> ans;
int main(){
    long long n, k;
    cin >> n >> k;
    ans.resize(n);
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        strong.push_back({q, i});
    }
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        ans[i] = q;
        money.push_back({q, strong[i].first});
    }
    sort(money.begin(), money.end());
    sort(strong.begin(), strong.end());
    for (long long i = strong.size() - 1; i >= 0; i--)
    {
        long long cnt = 0, cnt1 = 0;
        for (long long j = money.size() - 1; j >= 0; j--)
        {
            if (cnt1 == k)
                break;
            if (strong[i].first > money[j].second)
            {
                cnt += money[j].first;
                cnt1++;
            }
        }
        ans[strong[i].second] += cnt;
    }
    for (long long i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
    vector <pair <long long, long long> >money;
    vector <pair <long long, long long> >strong;
    vector <long long> realstrong;
    vector <long long> used;
    vector <long long> ans;
int main(){
    long long n, k;
    cin >> n >> k;
    used.resize(n, 0);
    ans.resize(n);
    realstrong.resize(n);
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        realstrong[i] = q;
        strong.push_back({q, i});
    }
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        money.push_back({q, i});
    }
    sort(money.begin(), money.end());
    sort(strong.begin(), strong.end());
    for (long long i = strong.size() - 1; i >= 0; i--)
    {
        used[strong[i].second] = true;
        long long cnt = 0, cnt1 = 0;
        for (long long j = money.size() - 1; j >= 0; j--)
        {
            if (cnt1 == k)
                break;
            if (!used[money[j].second] && realstrong[strong[i].second] > realstrong[money[j].second])
            {
                cnt += money[j].first;
                cnt1++;
            }
        }
        ans[strong[i].second] = cnt + money[strong[i].second].first;
    }
    for (long long i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
    vector <pair <long long, long long> >money;
    vector <pair <long long, long long> >strong;
    vector <long long> used;
    vector <long long> ans;
int main(){
    long long n, k;
    cin >> n >> k;
    used.resize(n, 0);
    ans.resize(n);
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        strong.push_back({q, i});
    }
    for (long long i = 0; i < n; i++)
    {
        long long q;
        cin >> q;
        money.push_back({q, i});
    }
    sort(money.begin(), money.end());
    sort(strong.begin(), strong.end());
    for (long long i = strong.size() - 1; i >= 0; i--)
    {
        used[strong[i].second] = true;
        long long cnt = 0, cnt1 = 0;
        for (long long j = money.size() - 1; j >= 0; j--)
        {
            if (cnt1 == k)
                break;
            if (!used[money[j].second] && strong[i].first > strong[j].first)
            {
                cnt += money[j].first;
                cnt1++;
            }
        }
        ans[strong[i].second] = cnt + money[strong[i].second].first;
    }
    for (long long i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
	if(a.first < b.first)
	{
		return 1;
	}
	else if(a.first ==b.first)
	{
		if(a.second<=b.second)
			return 1;
	}
	return 0;
}
bool comp(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
	if(a.first < b.first )
		return 1;
	return 0;
}
int main()
{
	ios::sync_with_stdio(0);
	ll n,k,i,j;
	cin >> n >> k;
	vector< pair<ll,ll> > a(n);
	vector< pair<ll,ll> >b(n);
	multimap<ll,ll>M;
	for(i=0;i<n;i++)
	{
		ll x;
		cin >> x;
		a[i].first = x;
		b[i].first = x;
	}
	for(i=0;i<n;i++)
	{
		ll x;
		cin >> x;
		a[i].second = x;
		b[i].second = x;
	}
	sort(b.begin(),b.end(),compare);
	cout << a[0].second << " ";
	for(i=1;i<n;i++)
	{
		ll tem = a[i].first;
		pair<ll,ll>P;
		P = make_pair(tem,0);
		ll index = (ll)distance(b.begin(),lower_bound(b.begin(),b.end(),P,comp));
		//cout << "index:" << tem << "\n";
		ll cnt=0,sum=a[i].second;
		index--;
		while(index>=0 && cnt<k)
		{
			sum+=b[index].second;
			cnt++;
			index--;
		}
		cout << sum << " ";
	}
	cout << "\n";
	return 0;
}