import heapq
import sys
import collections

class PersonJob:
    def __init__(self, person_index, total_hours):
        self.person_index = person_index
        self.total_hours = total_hours

    def __lt__(self, other):
        if self.total_hours == other.total_hours:
            return self.person_index < other.person_index
        return self.total_hours < other.total_hours

def main():
    input = sys.stdin.read
    data = list(map(int, input().split()))

    n = data[0]
    index = 1

    queue2 = []
    m = data[index]
    index += 1

    for i in range(m):
        heapq.heappush(queue2, -data[index])
        index += 1

    queue1 = []
    arr = []

    for i in range(n):
        total_hours = -heapq.heappop(queue2)
        person_job = PersonJob(i, total_hours)
        heapq.heappush(queue1, person_job)
        arr.append(person_job)

    for i in range(n, m):
        next_job_hours = -heapq.heappop(queue2)
        done_job = heapq.heappop(queue1)
        done_job.total_hours += next_job_hours
        heapq.heappush(queue1, done_job)

    out = []

    for i in range(n):
        out.append(arr[i].total_hours)

    print(' '.join(map(str, out)))

if __name__ == "__main__":
    main()
 
by