import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = in.readIntArray(1, n);
            Arrays.sort(a);
            long[] preSum = new long[n + 1];
            for (int i = 1; i <= n; ++i) {
                preSum[i] = preSum[i - 1] + a[i];
            }
            long[] result = new long[n + 1];
            for (int i = 1; i <= n; ++i) {
                if (i <= m) {
                    result[i] = preSum[i];
                } else {
                    result[i] = preSum[i] + result[i - m];
                }
            }
            for (int i = 1; i <= n; ++i) {
                out.print(result[i] + " ");
            }
        }

    }

    static class InputReader {
        final private int BUFFER_SIZE = 1 << 10;
        private DataInputStream in;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public InputReader(InputStream inputStream) {
            this.in = new DataInputStream(inputStream);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int[] readIntArray(int start, int n) {
            int ret[] = new int[start + n];
            for (int i = start; i < start + n; ++i) {
                ret[i] = this.nextInt();
            }
            return ret;
        }

        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
                if (bytesRead == -1)
                    buffer[0] = -1;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = in.readIntArray(1, n);
            Arrays.sort(a);
            int[] preSum = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                preSum[i] = preSum[i - 1] + a[i];
            }
            long[] result = new long[n + 1];
            for (int i = 1; i <= n; ++i) {
                if (i <= m) {
                    result[i] = preSum[i];
                } else {
                    result[i] = preSum[i] + result[i - m];
                }
            }
            for (int i = 1; i <= n; ++i) {
                out.print(result[i] + " ");
            }
        }

    }

    static class InputReader {
        final private int BUFFER_SIZE = 1 << 10;
        private DataInputStream in;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public InputReader(InputStream inputStream) {
            this.in = new DataInputStream(inputStream);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int[] readIntArray(int start, int n) {
            int ret[] = new int[start + n];
            for (int i = start; i < start + n; ++i) {
                ret[i] = this.nextInt();
            }
            return ret;
        }

        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
                if (bytesRead == -1)
                    buffer[0] = -1;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = in.readIntArray(1, n);
            Arrays.sort(a);
            int[] preSum = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                preSum[i] = preSum[i - 1] + a[i];
            }
            int[] result = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                if (i <= m) {
                    result[i] = preSum[i];
                } else {
                    result[i] = preSum[i] + result[i - m];
                }
            }
            for (int i = 1; i <= n; ++i) {
                out.print(result[i] + " ");
            }
        }

    }

    static class InputReader {
        final private int BUFFER_SIZE = 1 << 10;
        private DataInputStream in;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public InputReader(InputStream inputStream) {
            this.in = new DataInputStream(inputStream);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int[] readIntArray(int start, int n) {
            int ret[] = new int[start + n];
            for (int i = start; i < start + n; ++i) {
                ret[i] = this.nextInt();
            }
            return ret;
        }

        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
                if (bytesRead == -1)
                    buffer[0] = -1;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}


import java.io.*;
import java.util.*;
public class C1253 {
    public static void main(String args[])throws IOException
        {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int m=sc.nextInt();
            long sum[]=new long[n+1];
            long a[]=new long[n+1];
            int arr[]=new int[n+1];
            for(int i=1;i<=n;i++)
            {
                arr[i]=sc.nextInt();
            }
            Arrays.sort(arr);
            for(int i=1;i<=n;i++)
            {
                sum[i]=sum[i-1]+arr[i];
                if(i<=m)
                {
                    a[i]=sum[i];
                }
                else
                {
                    a[i]=sum[i]+a[i-m];
                }
                System.out.print(a[i]+" ");
            }
        }

}


import java.io.*;
import java.util.*;
public class C1253 {
    public static void main(String args[])throws IOException
        {
            Reader sc=new Reader();
            PrintWriter pw=new PrintWriter(System.out);
            int n=sc.nextInt();
            int m=sc.nextInt();
            long sum[]=new long[n+1];
            long a[]=new long[n+1];
            int arr[]=new int[n+1];
            for(int i=1;i<=n;i++)
            {
                arr[i]=sc.nextInt();
            }
            Arrays.sort(arr);
            for(int i=1;i<=n;i++)
            {
                sum[i]=sum[i-1]+arr[i];
                if(i<=m)
                {
                    a[i]=sum[i];
                }
                else
                {
                    a[i]=sum[i]+a[i-m];
                }
                pw.print(a[i]+" ");
            }
            pw.close();
        }

}
class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte [] buffer;
		private int bufferPointer, bytesRead;

		public Reader () {
			din = new DataInputStream (System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader (String file_name) throws IOException {
			din = new DataInputStream (new FileInputStream (file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine () throws IOException {
			byte [] buf = new byte[1024];
			int cnt = 0, c;
			while ((c = read ()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String (buf, 0, cnt);
		}

		public int nextInt () throws IOException {
			int ret = 0;
			byte c = read ();
			while (c <= ' ')
				c = read ();
			boolean neg = (c == '-');
			if (neg)
				c = read ();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read ()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong () throws IOException {
			long ret = 0;
			byte c = read ();
			while (c <= ' ')
				c = read ();
			boolean neg = (c == '-');
			if (neg)
				c = read ();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read ()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble () throws IOException {
			double ret = 0, div = 1;
			byte c = read ();
			while (c <= ' ')
				c = read ();
			boolean neg = (c == '-');
			if (neg)
				c = read ();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read ()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read ()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer () throws IOException {
			bytesRead = din.read (buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read () throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer ();
			return buffer[bufferPointer++];
		}

		public void close () throws IOException {
			if (din == null)
				return;
			din.close ();
		}
	}


// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args)
	{
		FastReader sc=new FastReader();
	    int n=sc.nextInt();
        int m=sc.nextInt();
        int arr[]=new int[n+1];
        long ans[]=new long[n+1];
        long dp[]=new long[n+1];
        for(int i=1;i<=n;i++) arr[i]=sc.nextInt();
        Arrays.sort(arr);
        dp[0]=0;
        for(int i=1;i<=n;i++){
            if(i <= m)
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i];
                System.out.print(dp[i]+" ");
            }
            else
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i]+ans[i-m];
                System.out.print(ans[i]+" ");
            }

        }
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

}


import java.util.*;
public class main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int arr[]=new int[n+1];
        long ans[]=new long[n+1];
        long dp[]=new long[n+1];

        for(int i=1;i<=n;i++) arr[i]=sc.nextInt();
        Arrays.sort(arr);
        dp[0]=0;
        for(int i=1;i<=n;i++){
            if(i <= m)
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i];
                System.out.print(dp[i]+" ");
            }
            else
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i]+ans[i-m];
                System.out.print(ans[i]+" ");
            }

        }
    }
}


// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args)
	{
		FastReader sc=new FastReader();
	    int n=sc.nextInt();
        int m=sc.nextInt();
        int arr[]=new int[n+1];
        long ans[]=new long[n+1];
        long dp[]=new long[n+1];
        for(int i=1;i<=n;i++) arr[i]=sc.nextInt();
        Arrays.sort(arr);
        dp[0]=0;
        for(int i=1;i<=n;i++){
            if(i <= m)
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i];
                System.out.print(dp[i]+" ");
            }
            else
            {
                dp[i]=dp[i-1]+arr[i];
                ans[i]=dp[i]+ans[i-m];
                System.out.print(ans[i]+" ");
            }

        }
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.StringTokenizer;

public class problem3 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        ArrayList<Integer> list = new ArrayList<>();
        tokenizer = new StringTokenizer(reader.readLine());
        for (int i = 0; i < n; i++) {
            list.add(Integer.parseInt(tokenizer.nextToken()));
        }
        list.sort(Comparator.naturalOrder());
        long sum = 0;
        long add = 0;
        long tmp = 0;
        sum+=list.get(0);
        System.out.print(sum+" ");
        for (int i = 1; i < n; i++) {
            if(i < m){
                sum+=list.get(i);
                System.out.print(sum+" ");
            }else{
                /*if(i % m == 0){
                    add+=list.get((i-m));;
                    sum += list.get(i) + add;
                }else {
                    sum += list.get(i) + add + list.get(i % m);
                }
                System.out.print(sum+" ");*/
                sum+=list.get(i);
                for(int j = 0; j < i/m; j++){
                    sum+=list.get(j*m+i%m);
                }
                System.out.print(sum+" ");
            }
            /*if(i % m != 0){
                sum+=list.get(i);
                System.out.print(sum+" ");
            }else{
                sum+=list.get(i);
                /*for(int j = 0; j < i/m; j++){
                    sum+=list.get(j*m);
                }
                add+=list.get(i/m-1);
                sum+=add;
                System.out.print(sum+" ");
            }*/
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.StringTokenizer;

public class problem3 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        ArrayList<Integer> list = new ArrayList<>();
        tokenizer = new StringTokenizer(reader.readLine());
        for (int i = 0; i < n; i++) {
            list.add(Integer.parseInt(tokenizer.nextToken()));
        }
        list.sort(Comparator.naturalOrder());
        long sum = 0;
        long add = 0;
        long tmp = 0;
        int[] adds = new int[m];
        for (int i = 0; i < n; i++) {
            if(i < m){
                sum+=list.get(i);
                System.out.print(sum+" ");
            }else{
                /*if(i % m == 0){
                    add+=list.get((i-m));;
                    sum += list.get(i) + add;
                }else {
                    sum += list.get(i) + add + list.get(i % m);
                }
                System.out.print(sum+" ");*/
                adds[i%m]+=list.get(i-m);
                sum+=list.get(i)+adds[i%m];

                /*for(int j = 0; j < i/m; j++){
                    sum+=list.get(j*m+i%m);
                }*/
                System.out.print(sum+" ");
            }
            /*if(i % m != 0){
                sum+=list.get(i);
                System.out.print(sum+" ");
            }else{
                sum+=list.get(i);
                /*for(int j = 0; j < i/m; j++){
                    sum+=list.get(j*m);
                }
                add+=list.get(i/m-1);
                sum+=add;
                System.out.print(sum+" ");
            }*/
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class problem3 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        int[] list = new int[n];
        tokenizer = new StringTokenizer(reader.readLine());
        for (int i = 0; i < n; i++) {
            list[i] = (Integer.parseInt(tokenizer.nextToken()));
        }
        Arrays.sort(list);
        long sum = 0;
        long[] adds = new long[m];
        for (int i = 0; i < n; i++) {
            if(i < m){
                sum+=list[i];
            }else{
                adds[i % m]+=list[i-m];
                sum+=list[i]+adds[i%m];
            }
            System.out.print(sum+" ");
        }
    }
}


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

public class sweets {
	public static void main(String[] args) {
		FastScanner scan=new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=scan.nextInt(), m=scan.nextInt();
		long[] a=new long[n];
		for(int i=0;i<n;i++) a[i]=scan.nextInt();
		Arrays.sort(a);

		long[] delta=new long[m];
		long[] res=new long[n];

		int mod=0;
		for(int i=0;i<n;i++) {
			if(i>0) res[i]=res[i-1];
			res[i]+=a[i];
			res[i]+=delta[mod];
			delta[mod]+=a[i];
			mod++;
			if(mod==m) mod=0;
		}
		for(long i:res) {
			out.print(i);
			out.print(" ");
		}
		out.close();
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception 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 line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class sweets {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(), m=scan.nextInt();
		long[] a=new long[n];
		for(int i=0;i<n;i++) a[i]=scan.nextInt();
		Arrays.sort(a);

		long[] delta=new long[m];
		long[] res=new long[n];

		int mod=0;
		for(int i=0;i<n;i++) {
			if(i>0) res[i]=res[i-1];
			res[i]+=a[i];
			res[i]+=delta[mod];
			delta[mod]+=a[i];
			mod=(mod+1)%m;
		}
		for(long i:res) System.out.print(i+" ");
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class sweets {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(), m=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) a[i]=scan.nextInt();
		Arrays.sort(a);

		int[] delta=new int[m];
		int[] res=new int[n];

		int mod=0;
		for(int i=0;i<n;i++) {
			if(i>0) res[i]=res[i-1];
			res[i]+=a[i];
			res[i]+=delta[mod];
			delta[mod]+=a[i];
			mod=(mod+1)%m;
		}
		for(int i:res) System.out.print(i+" ");
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class sweets {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(), m=scan.nextInt();
		long[] a=new long[n];
		for(int i=0;i<n;i++) a[i]=scan.nextInt();
		Arrays.sort(a);

		long[] delta=new long[m];
		long[] res=new long[n];

		int mod=0;
		for(int i=0;i<n;i++) {
			if(i>0) res[i]=res[i-1];
			res[i]+=a[i];
			res[i]+=delta[mod];
			delta[mod]+=a[i];
			mod++;
			if(mod==m) mod=0;
		}
		for(long i:res) System.out.print(i+" ");
	}
}


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

public class P1253C
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        long[] arr = new long[n];
        st = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++)
            arr[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(arr);

        long[] modSum = new long[m];
        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            modSum[i % m] += arr[i];
            sum += modSum[i % m];
            System.out.print((i == 0 ? "" : " ") + sum);
        }
        System.out.println();
    }
}


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

public class P1253C
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        int[] arr = new int[n];
        st = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++)
            arr[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(arr);

        int[] modSum = new int[m];
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            modSum[i % m] += arr[i];
            sum += modSum[i % m];
            System.out.print((i == 0 ? "" : " ") + sum);
        }
        System.out.println();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class hello1
 {static class FastReader
       {
           BufferedReader br;
           StringTokenizer st;

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

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

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

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

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

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

       }

    static String sum (String s)
    {
        String s1 = "";

        if(s.contains("a"))
            s1+="a";
        if(s.contains("e"))
            s1+="e";
        if(s.contains("i"))
            s1+="i";
        if(s.contains("o"))
            s1+="o";
        if(s.contains("u"))
            s1+="u";

            return s1;

    }

    public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm)
    {
        // Create a list from elements of HashMap
        List<Map.Entry<String, Integer> > list =
               new LinkedList<Map.Entry<String, Integer> >(hm.entrySet());

        // Sort the list
        Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
            public int compare(Map.Entry<String, Integer> o1,
                               Map.Entry<String, Integer> o2)
            {
                return (o1.getValue()).compareTo(o2.getValue());
            }
        });

        // put data from sorted list to hashmap
        HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>();
        for (Map.Entry<String, Integer> aa : list) {
            temp.put(aa.getKey(), aa.getValue());
        }
        return temp;
    }

public static void main(String args[])
    {

	FastReader input = new FastReader();

	int n = input.nextInt();

	int m = input.nextInt();

	int a[] = new int[n];
	long ans[] = new long[n];
	for(int i=0;i<n;i++)
	{
		a[i] = input.nextInt();

	}

	Arrays.sort(a);
	int i=0;
	int j=0;
	int d = 1;
	long sum =0;
	for(int k=0;k<n;k++)
	{

		sum+=a[k];
		ans[k] = sum;
		if(k>=m)
		{
			ans[k]+=ans[k-m];
		}

	}

	for(i=0;i<n;i++)
	{
		System.out.print(ans[i] + " ");
	}

		// 2 4 6 8 10 -5
		// 5 10 - 2

		// 5 10 15 20 25 30 35  -7
		// 8 16 24 32 -4

		// 6
		// (2)
		// (1)

  }
static int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

static boolean find(int a[],int A,int B)
	{
		if( root(a,A)==root(a,B) )       //if A and B have the same root, it means that they are connected.
			return true;
		else
			return false;
	}

static boolean method(StringBuilder sb , int n, int count){

	for(int i=sb.length()-1 ; i>=0 ;i--){
		if((sb.charAt(i)-'0')%3==n){
			sb.deleteCharAt(i);
			count--;
			if(count==0)
				break;
		}
	}

	if(sb.length()==0)
		return false;

	while(sb.charAt(0)=='0' && sb.length()>1){
		sb.deleteCharAt(0);
	}

	if(count==0 && sb.length()>0)
		return true;
	return false;
}

	static void union(int Arr[ ],int size[ ],int A,int B)
	{
		int root_A = root(Arr,A);
		int root_B = root(Arr,B);

		if(root_A == root_B)
		{
			return;
		}
		if(size[root_A] < size[root_B] )
		{
			Arr[ root_A ] = Arr[root_B];
			size[root_B] += size[root_A];
			size[root_A] = 0;

		}
		else
		{
			Arr[ root_B ] = Arr[root_A];
			size[root_A] += size[root_B];
			size[root_B] = 0;

		}

	}

	static int root (int Arr[ ] ,int i)
	{
		while(Arr[ i ] != i)
        {
			i = Arr[ i ];
        }
        return i;
	}
 }

 class Pair
 {
     int a;
     int b;
     Pair(int a,int b)
     {
         this.a=a;
         this.b=b;
     }
 }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class hello1
 {static class FastReader
       {
           BufferedReader br;
           StringTokenizer st;

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

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

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

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

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

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

       }

    static String sum (String s)
    {
        String s1 = "";

        if(s.contains("a"))
            s1+="a";
        if(s.contains("e"))
            s1+="e";
        if(s.contains("i"))
            s1+="i";
        if(s.contains("o"))
            s1+="o";
        if(s.contains("u"))
            s1+="u";

            return s1;

    }

    public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm)
    {
        // Create a list from elements of HashMap
        List<Map.Entry<String, Integer> > list =
               new LinkedList<Map.Entry<String, Integer> >(hm.entrySet());

        // Sort the list
        Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
            public int compare(Map.Entry<String, Integer> o1,
                               Map.Entry<String, Integer> o2)
            {
                return (o1.getValue()).compareTo(o2.getValue());
            }
        });

        // put data from sorted list to hashmap
        HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>();
        for (Map.Entry<String, Integer> aa : list) {
            temp.put(aa.getKey(), aa.getValue());
        }
        return temp;
    }

public static void main(String args[])
    {

	FastReader input = new FastReader();

	int n = input.nextInt();

	int m = input.nextInt();

	int a[] = new int[n];
	for(int i=0;i<n;i++)
	{
		a[i] = input.nextInt();

	}

	Arrays.sort(a);
	int i=0;
	int j=0;
	int d = 1;
	long sum =0;
	for(int k=1;k<=n;k++)
	{

		sum =0;
		d = 1;
		j=0;
		i=0;
		int x = k-1;
		while(j<k)//k=2,j=0 loop=2
		{
			// 1
			if(i>=m)//i=0 m=2
			{

				i=0;
				d++;
			}
			sum+=d*a[x];
			j++;
			i++;

			x--;

		}
		System.out.print(sum + " ");

	}

		// 2 4 6 8 10 -5
		// 5 10 - 2

		// 5 10 15 20 25 30 35  -7
		// 8 16 24 32 -4

		// 6
		// (2)
		// (1)

  }
static int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

static boolean find(int a[],int A,int B)
	{
		if( root(a,A)==root(a,B) )       //if A and B have the same root, it means that they are connected.
			return true;
		else
			return false;
	}

static boolean method(StringBuilder sb , int n, int count){

	for(int i=sb.length()-1 ; i>=0 ;i--){
		if((sb.charAt(i)-'0')%3==n){
			sb.deleteCharAt(i);
			count--;
			if(count==0)
				break;
		}
	}

	if(sb.length()==0)
		return false;

	while(sb.charAt(0)=='0' && sb.length()>1){
		sb.deleteCharAt(0);
	}

	if(count==0 && sb.length()>0)
		return true;
	return false;
}

	static void union(int Arr[ ],int size[ ],int A,int B)
	{
		int root_A = root(Arr,A);
		int root_B = root(Arr,B);

		if(root_A == root_B)
		{
			return;
		}
		if(size[root_A] < size[root_B] )
		{
			Arr[ root_A ] = Arr[root_B];
			size[root_B] += size[root_A];
			size[root_A] = 0;

		}
		else
		{
			Arr[ root_B ] = Arr[root_A];
			size[root_A] += size[root_B];
			size[root_B] = 0;

		}

	}

	static int root (int Arr[ ] ,int i)
	{
		while(Arr[ i ] != i)
        {
			i = Arr[ i ];
        }
        return i;
	}
 }

 class Pair
 {
     int a;
     int b;
     Pair(int a,int b)
     {
         this.a=a;
         this.b=b;
     }
 }


/**
 * Date: 16 Nov, 2019
 * Link: https://codeforces.com/contest/1253/problem/C
 *
 * @author Prasad Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class C_1253 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        int n = in.ni();
        int m = in.ni();
        int a[] = in.gia(n);
        Data.sort(a);
        long m_sum[] = new long[n];
        for (int i = 0; i < n; i++) {
            m_sum[i] += a[i];
            if (i - m >= 0) {
                m_sum[i] += m_sum[i - m];
            }
        }
        long ans[] = new long[n];
        long p = 0;
        for (int i = n - 1; i >= 0; i--) {
            p += (1l * a[i] * ((n - 1 - i) / m)) + a[i];
        }
        ans[n - 1] = p;
        for (int i = n - 2; i >= 0; i--) {
            ans[i] = ans[i + 1] - m_sum[i + 1];
        }
        for (long i : ans) {
            in.println(i);
        }
        in.bw.flush();
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        public void print(int s) throws IOException {
            bw.write(s + "");
        }

        public void println(int s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(long s) throws IOException {
            bw.write(s + "");
        }

        public void println(long s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(double s) throws IOException {
            bw.write(s + "");
        }

        public void println(double s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}


/**
 * Date: 16 Nov, 2019
 * Link: https://codeforces.com/contest/1253/problem/C
 *
 * @author Prasad Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class C_1253 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        int n = in.ni();
        int m = in.ni();
        int a[] = in.gia(n);
        Data.sort(a);
        long m_sum[] = new long[n];
        for (int i = 0; i < n; i++) {
            m_sum[i] += a[i];
            if (i - m >= 0) {
                m_sum[i] += m_sum[i - m];
            }
        }
        // for (int i = 0; i < n; i++) {
        //     System.out.print(m_sum[i] + " ");
        // }
        // System.out.println();
        long ans[] = new long[n];
        long p = 0;
        for (int i = n - 1; i >= 0; i--) {
            p += (a[i] * ((n - 1 - i) / m)) + a[i];
        }
        // System.out.println(p);
        ans[n - 1] = p;
        for (int i = n - 2; i >= 0; i--) {
            ans[i] = ans[i + 1] - m_sum[i + 1];
        }
        for (long i : ans) {
            System.out.println(i);
        }
        in.bw.flush();
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        public void print(int s) throws IOException {
            bw.write(s + "");
        }

        public void println(int s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(long s) throws IOException {
            bw.write(s + "");
        }

        public void println(long s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(double s) throws IOException {
            bw.write(s + "");
        }

        public void println(double s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}


/**
 * Date: 16 Nov, 2019
 * Link: https://codeforces.com/contest/1253/problem/C
 *
 * @author Prasad Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class C_1253 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        int n = in.ni();
        int m = in.ni();
        int a[] = in.gia(n);
        Data.sort(a);
        long m_sum[] = new long[n];
        for (int i = 0; i < n; i++) {
            m_sum[i] += a[i];
            if (i - m >= 0) {
                m_sum[i] += m_sum[i - m];
            }
        }
        long ans[] = new long[n];
        long p = 0;
        for (int i = n - 1; i >= 0; i--) {
            p += (a[i] * ((n - 1 - i) / m)) + a[i];
        }
        ans[n - 1] = p;
        for (int i = n - 2; i >= 0; i--) {
            ans[i] = ans[i + 1] - m_sum[i + 1];
        }
        for (long i : ans) {
            in.println(i);
        }
        in.bw.flush();
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][] { adja, weight };
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        public void print(int s) throws IOException {
            bw.write(s + "");
        }

        public void println(int s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(long s) throws IOException {
            bw.write(s + "");
        }

        public void println(long s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(double s) throws IOException {
            bw.write(s + "");
        }

        public void println(double s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Scanner;

public class SweetsEating {

    public void print(int arr[], int k) {

        Arrays.sort(arr);
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            res[i] = total(arr, i , k);
        }
        for(int i : res) {
            System.out.print( i + " ");
        }
    }

    public int total(int arr[], int val, int k) {

        if((val + 1)<=k) {
            int totalsum = 0;
            for(int i = 0; i <=val; i++) {
                totalsum = totalsum + arr[i];
            }
            return totalsum;
        } else {
            int j = val;
            int track = 1;
            int totalSum = 0;

            while (j>=0) {
                int modify = k;
                int localSum = 0;
                while (modify > 0 && j >= 0) {
                    localSum = localSum + arr[j]*track;
                    modify--;
                    j--;
                }
                totalSum = totalSum + localSum;
                track++;
            }
            return totalSum;
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        int arr[] = new int[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class SweetsEating {

    public void suffle(int arr[]) {
        Random r = new Random();

        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = arr.length-1; i > 0; i--) {

            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);

            // Swap arr[i] with the element at random index
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    public void print(int arr[], int k) {

        suffle(arr);
        Arrays.sort(arr);

        long pref[] = new long[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        long res[] = new long[arr.length];
        for(int i = 0; i < arr.length; i++) {
            if((i-k)>=0) {
                res[i] = pref[i] + res[i-k];
            } else {
                res[i] = pref[i];
            }
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        int arr[] = new int[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Scanner;

public class SweetsEating {

    public void print(Integer arr[], int k) {

        Arrays.sort(arr);

        int pref[] = new int[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            res[i] = total(arr, i , k, pref);
        }
        for(int i : res) {
            System.out.print( i + " ");
        }
    }

    public int total(Integer arr[], int val, int k, int pref[]) {

        if((val + 1)<=k) {
            int totalsum = 0;
            for(int i = 0; i <=val; i++) {
                totalsum = totalsum + arr[i];
            }
            return totalsum;
        } else {
            int j = val;
            int track = 1;
            int totalSum = 0;
            int p = k;
            while (j>=0) {
                if((j-p)>=0) {
                    totalSum = totalSum + pref[j];
                    j = j - p;
                } else {
                    totalSum = totalSum + pref[j];
                     j = -1;
                    break;
                }
            }
            return totalSum;
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        Integer arr[] = new Integer[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class SweetsEating {

    public void suffle(int arr[]) {
        Random r = new Random();

        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = arr.length-1; i > 0; i--) {

            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);

            // Swap arr[i] with the element at random index
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    public void print(int arr[], int k) {

        suffle(arr);
        Arrays.sort(arr);

        int pref[] = new int[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            if((i-k)>=0) {
                res[i] = pref[i] + res[i-k];
            } else {
                res[i] = pref[i];
            }
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        int arr[] = new int[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class SweetsEating {

    public void suffle(int arr[]) {
        Random r = new Random();

        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = arr.length-1; i > 0; i--) {

            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);

            // Swap arr[i] with the element at random index
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    public void print(int arr[], int k) {

        suffle(arr);
        Arrays.sort(arr);

        int pref[] = new int[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        long res[] = new long[arr.length];
        for(int i = 0; i < arr.length; i++) {
            if((i-k)>=0) {
                res[i] = pref[i] + res[i-k];
            } else {
                res[i] = pref[i];
            }
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        int arr[] = new int[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Scanner;

public class SweetsEating {

    public void print(Integer arr[], int k) {

        Arrays.sort(arr);
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            res[i] = total(arr, i , k);
        }
        for(int i : res) {
            System.out.print( i + " ");
        }
    }

    public int total(Integer arr[], int val, int k) {

        if((val + 1)<=k) {
            int totalsum = 0;
            for(int i = 0; i <=val; i++) {
                totalsum = totalsum + arr[i];
            }
            return totalsum;
        } else {
            int j = val;
            int track = 1;
            int totalSum = 0;

            while (j>=0) {
                int modify = k;
                int localSum = 0;
                while (modify > 0 && j >= 0) {
                    localSum = localSum + arr[j]*track;
                    modify--;
                    j--;
                }
                totalSum = totalSum + localSum;
                track++;
            }
            return totalSum;
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        Integer arr[] = new Integer[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Scanner;

public class SweetsEating {

    public void print(Integer arr[], int k) {

        Arrays.sort(arr);

        int pref[] = new int[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            res[i] = total(arr, i , k, pref);
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public int total(Integer arr[], int val, int k, int pref[]) {

        if((val + 1)<=k) {
            int totalsum = 0;
            for(int i = 0; i <=val; i++) {
                totalsum = totalsum + arr[i];
            }
            return totalsum;
        } else {
            int j = val;
            int track = 1;
            int totalSum = 0;
            int p = k;
            while (j>=0) {
                if((j-p)>=0) {
                    totalSum = totalSum + pref[j];
                    j = j - p;
                } else {
                    totalSum = totalSum + pref[j];
                     j = -1;
                    break;
                }
            }
            return totalSum;
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        Integer arr[] = new Integer[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class SweetsEating {

    public void suffle(long arr[]) {
        Random r = new Random();

        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = arr.length-1; i > 0; i--) {

            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);

            // Swap arr[i] with the element at random index
            long temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    public void print(long arr[], int k) {

        suffle(arr);
        Arrays.sort(arr);

        long pref[] = new long[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        long res[] = new long[arr.length];
        for(int i = 0; i < arr.length; i++) {
            if((i-k)>=0) {
                res[i] = pref[i] + res[i-k];
            } else {
                res[i] = pref[i];
            }
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        long arr[] = new long[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


//package codeforces.div2;

import java.util.Arrays;
import java.util.Scanner;

public class SweetsEating {

    public void print(Integer arr[], int k) {

        Arrays.sort(arr);

        int pref[] = new int[arr.length];
        pref[0] = arr[0];
        for(int i = 1; i < arr.length; i++) {
            pref[i] = pref[i-1] + arr[i];
        }
        int res[] = new int[arr.length];
        for(int i = 0; i < arr.length; i++) {
            if((i-k)>=0) {
                res[i] = pref[i] + res[i-k];
            } else {
                res[i] = pref[i];
            }
        }
        for(int i = 0; i < res.length; i++) {
            System.out.print( res[i]+ " ");
        }
    }

    public int total(Integer arr[], int val, int k, int pref[]) {

        if((val + 1)<=k) {
            int totalsum = 0;
            for(int i = 0; i <=val; i++) {
                totalsum = totalsum + arr[i];
            }
            return totalsum;
        } else {
            int j = val;
            int track = 1;
            int totalSum = 0;
            int p = k;
            while (j>=0) {
                if((j-p)>=0) {
                    totalSum = totalSum + pref[j];
                    j = j - p;
                } else {
                    totalSum = totalSum + pref[j];
                     j = -1;
                    break;
                }
            }
            return totalSum;
        }
    }

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int i = 0;
        Integer arr[] = new Integer[n];
        while ( i < n) {
            arr[i++] = sc.nextInt();
        }
        SweetsEating l  = new SweetsEating();
        l.print(arr, k);
    }
}


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

public class Solver {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        TaskC solver = new TaskC(in, out);
        solver.solveC();
        out.close();
    }

    static class TaskC {
        FastReader in;
        PrintWriter out;

        public TaskC(FastReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solveA() {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt();
                int[] arrayA = in.nextIntArray(n);
                int[] arrayB = in.nextIntArray(n);

                boolean start = false;
                boolean end = false;
                boolean possible = true;
                int diff = Integer.MIN_VALUE;

                for (int i = 0; i < n; i++) {
                    if (arrayA[i] != arrayB[i]) {
                        if (start && end) {
                            possible = false;
                            break;
                        }
                        int diffA = arrayB[i]-arrayA[i];
                        if (diffA < 0) {
                            possible = false;
                            break;
                        } else {
                            if (diff == Integer.MIN_VALUE) {
                                diff = diffA;
                                start = true;
                            } else {
                                if (diff != diffA) {
                                    possible = false;
                                    break;
                                }
                            }
                        }
                    } else if (start && !end) {
                        end = true;
                    }
                }

                out.println(possible ? "YES" : "NO");
            }
        }

        public void solveB() {
            int n = in.nextInt();
            int[] array = in.nextIntArray(n);

            int days = 0;
            int counter = 0;
            int eventCounter = 0;
            ArrayList<Integer> eventPerDay = new ArrayList<>();

            HashMap<Integer, Integer> map = new HashMap<>();

            for (int i : array) {
                eventCounter++;
                if (i > 0) {
                    if (map.containsKey(i)) {
                        days = -1;
                        break;
                    } else {
                        map.put(i, i);
                        counter += i;
                    }
                } else {
                    int posI = -1 * i;
                    if (!map.containsKey(posI) || map.get(posI) == 0) {
                        days = -1;
                        break;
                    } else {
                        counter -= posI;
                        if (counter == 0) {
                            eventPerDay.add(eventCounter);
                            days++;
                            map = new HashMap<>();
                            eventCounter = 0;
                        }
                    }
                }
            }

            if (days == -1 || counter != 0) {
                out.println(-1);
            } else {
                out.println(days);
                for (int i : eventPerDay) {
                    out.print(i + " ");
                }
            }
        }

        public void solveC() {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] array = in.nextIntArray(n);
            int[] arrayB = new int[n+1];
            Arrays.sort(array);

            for (int i = 1; i <= n; i++) {
                arrayB[i] = arrayB[i-1] + array[i-1];
            }

            for (int k = 1; k <= n; k++) {
                long day = 1;
                long sugar = 0;

                int j = k;
                for (; j-m >= 0; j=j-m, day++) {
                    sugar += (day * ( arrayB[j] - arrayB[j-m] ));
                }

                if (j > 0) {
                    sugar += (day * (arrayB[j] - arrayB[0]));
                }

                out.print(sugar + " ");
            }
        }
    }

    private static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    private static long lcm(long a, long b) {
        return (a * b) / gcd(a, b);
    }

    private static int min(int a, int b) {
        return a < b ? a : b;
    }

    private static int max(int a, int b) {
        return a > b ? a : b;
    }

    private static int min(ArrayList<Integer> list) {
        int min = Integer.MAX_VALUE;
        for (int el : list) {
            if (el < min) {
                min = el;
            }
        }
        return min;
    }

    private static int max(ArrayList<Integer> list) {
        int max = Integer.MIN_VALUE;
        for (int el : list) {
            if (el > max) {
                max = el;
            }
        }
        return max;
    }

    private static int min(int[] list) {
        int min = Integer.MAX_VALUE;
        for (int el : list) {
            if (el < min) {
                min = el;
            }
        }
        return min;
    }

    private static int max(int[] list) {
        int max = Integer.MIN_VALUE;
        for (int el : list) {
            if (el > max) {
                max = el;
            }
        }
        return max;
    }

    private static void fill(int[] array, int value) {
        for (int i = 0; i < array.length; i++) {
            array[i] = value;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }
    }
}


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

public class Solver {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        TaskC solver = new TaskC(in, out);
        solver.solveC();
        out.close();
    }

    static class TaskC {
        FastReader in;
        PrintWriter out;

        public TaskC(FastReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solveA() {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt();
                int[] arrayA = in.nextIntArray(n);
                int[] arrayB = in.nextIntArray(n);

                boolean start = false;
                boolean end = false;
                boolean possible = true;
                int diff = Integer.MIN_VALUE;

                for (int i = 0; i < n; i++) {
                    if (arrayA[i] != arrayB[i]) {
                        if (start && end) {
                            possible = false;
                            break;
                        }
                        int diffA = arrayB[i]-arrayA[i];
                        if (diffA < 0) {
                            possible = false;
                            break;
                        } else {
                            if (diff == Integer.MIN_VALUE) {
                                diff = diffA;
                                start = true;
                            } else {
                                if (diff != diffA) {
                                    possible = false;
                                    break;
                                }
                            }
                        }
                    } else if (start && !end) {
                        end = true;
                    }
                }

                out.println(possible ? "YES" : "NO");
            }
        }

        public void solveB() {
            int n = in.nextInt();
            int[] array = in.nextIntArray(n);

            int days = 0;
            int counter = 0;
            int eventCounter = 0;
            ArrayList<Integer> eventPerDay = new ArrayList<>();

            HashMap<Integer, Integer> map = new HashMap<>();

            for (int i : array) {
                eventCounter++;
                if (i > 0) {
                    if (map.containsKey(i)) {
                        days = -1;
                        break;
                    } else {
                        map.put(i, i);
                        counter += i;
                    }
                } else {
                    int posI = -1 * i;
                    if (!map.containsKey(posI) || map.get(posI) == 0) {
                        days = -1;
                        break;
                    } else {
                        counter -= posI;
                        if (counter == 0) {
                            eventPerDay.add(eventCounter);
                            days++;
                            map = new HashMap<>();
                            eventCounter = 0;
                        }
                    }
                }
            }

            if (days == -1 || counter != 0) {
                out.println(-1);
            } else {
                out.println(days);
                for (int i : eventPerDay) {
                    out.print(i + " ");
                }
            }
        }

        public void solveC() {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] array = in.nextIntArray(n);
            int[] arrayB = new int[n+1];
            Arrays.sort(array);

            for (int i = 1; i <= n; i++) {
                arrayB[i] = arrayB[i-1] + array[i-1];
            }

            for (int k = 1; k <= n; k++) {
                int day = 1;
                long sugar = 0;

                int j = k;
                for (; j-m >= 0; j=j-m, day++) {
                    sugar += (day * ( arrayB[j] - arrayB[j-m] ));
                }

                if (j > 0) {
                    sugar += (day * (arrayB[j] - arrayB[0]));
                }

                out.print(sugar + " ");
            }
        }
    }

    private static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    private static long lcm(long a, long b) {
        return (a * b) / gcd(a, b);
    }

    private static int min(int a, int b) {
        return a < b ? a : b;
    }

    private static int max(int a, int b) {
        return a > b ? a : b;
    }

    private static int min(ArrayList<Integer> list) {
        int min = Integer.MAX_VALUE;
        for (int el : list) {
            if (el < min) {
                min = el;
            }
        }
        return min;
    }

    private static int max(ArrayList<Integer> list) {
        int max = Integer.MIN_VALUE;
        for (int el : list) {
            if (el > max) {
                max = el;
            }
        }
        return max;
    }

    private static int min(int[] list) {
        int min = Integer.MAX_VALUE;
        for (int el : list) {
            if (el < min) {
                min = el;
            }
        }
        return min;
    }

    private static int max(int[] list) {
        int max = Integer.MIN_VALUE;
        for (int el : list) {
            if (el > max) {
                max = el;
            }
        }
        return max;
    }

    private static void fill(int[] array, int value) {
        for (int i = 0; i < array.length; i++) {
            array[i] = value;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }
    }
}