Logo
(追記) (追記ここまで)

16594번 - A Study on Groups 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB118514745.192%

문제

You are given a bag of N integers, and you are to put these integers into M distinct groups. When you distribute the integers, you have to make sure that each integer belongs to exactly one group and the size of any two different groups differs by at most 1.

The cost of a group is equal to the lowest integer in that group, while the total cost of M groups simply equals to the summation of the cost of each group. Note that the cost of an empty group is zero.

Now, your task in this problem is to find a way to put N given integers (not necessarily unique) into M distinct groups such that the total cost of those groups is minimum. Also, find a way such that the total cost is maximum. Output only the total costs.

입력

Input begins with two integers: N M (1 ≤ N, M ≤ 100000) representing the number of given integers and the number of groups to be made, respectively. The next line contains N integers: Ai (0 ≤ Ai ≤ 1000000) representing the given integers.

출력

Output in a line two integers (separated by a single space) representing the minimum total cost and the maximum total cost, respectively.

제한

예제 입력 1

7 3
4 2 7 1 3 5 6

예제 출력 1

6 11

The minimum total cost can be obtained from {(6, 3, 5),(4, 1),(2, 7)} with a total cost of 3 + 1 + 2 = 6.

The maximum total cost can be obtained from {(4, 5),(7, 6),(2, 1, 3)} with a total cost of 4 + 6 + 1 = 11.

예제 입력 2

5 1
10 15 17 4 8

예제 출력 2

4 4

예제 입력 3

3 2
470 105 222

예제 출력 3

327 575

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2018 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /