PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000100. Doanh thu sân bay (Airport)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Doanh thu sân bay (Airport)

Airport

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are mm aircraft with aia_i empty seats and nn passengers purchasing tickets one after another. A ticket on a plane with x>0x>0 currently empty seats costs exactly xx units, and then the seat count decreases. Each passenger may choose any plane with an empty seat. Find maximum and minimum total revenue.

Input

Line 1 contains n,mn,m. Line 2 contains mm integers aia_i.

Output

Print two integers on one line: maximum revenue and then minimum revenue.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤61\le n,m\le 6; 1≤ai≤10001\le a_i\le1000; ∑iai≥n\sum_i a_i\ge n.
  • Subtask 2 (30 points): 1≤n,m≤1001\le n,m\le 100; 1≤ai≤10001\le a_i\le1000; ∑iai≥n\sum_i a_i\ge n.
  • Subtask 3 (50 points): 1≤n,m≤10001\le n,m\le 1000; 1≤ai≤10001\le a_i\le1000; ∑iai≥n\sum_i a_i\ge n.

Examples

Input

4 3
2 2 2

Output

7 6

Explanation

Maximum revenue is 2+2+2+1=72+2+2+1=7 by selling first seats on three planes. Minimum is 2+1+2+1=62+1+2+1=6 by exhausting one plane before moving to another.