program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
const smax=99;
type large=array[0..99] of LongInt;
var data:large; n, k, i, min, max:smallint;
procedure swap(Var a, b:LongInt);
var t:LongInt;
begin
t:=a;
a:=b;
b:=t;
end;
procedure writeArr(arr:large; n:SmallInt);
Var i:smallint;
begin
for i:=0 to n-1 do write(arr[i], ' ');
Writeln;
end;
procedure bubbleSort(Var arr:large; n:smallint);
Var i, j:smallint;
begin
for i:=0 to n do begin
for j:=i to n do begin
if arr[i]>arr[j] then swap(arr[i], arr[j]);
end;
end;
end;
function isArithProgress(arr:large):boolean;
Var i:smallint; res:boolean;
begin
res:=True;
for i:=1 to n-1 do if (arr[i]-arr[i-1])<>(arr[i+1]-arr[i]) then res:=False;
isArithProgress := res;
end;
begin
min:=0;
max:=0;
read(n);
n:=n-1;
for i:=0 to n do read(data[i]);
read(k);
bubbleSort(data, n);
for i:=0 to k-1 do begin min:=min+data[i]; max:=max+data[n-i] end;
write(min, ' ', max);
end.
cHJvZ3JhbSBQcm9qZWN0MTsKCnskQVBQVFlQRSBDT05TT0xFfQoKdXNlcwogIFN5c1V0aWxzOwoKY29uc3Qgc21heD05OTsKdHlwZSBsYXJnZT1hcnJheVswLi45OV0gb2YgTG9uZ0ludDsKdmFyIGRhdGE6bGFyZ2U7IG4sIGssIGksIG1pbiwgbWF4OnNtYWxsaW50OwoKcHJvY2VkdXJlIHN3YXAoVmFyIGEsIGI6TG9uZ0ludCk7CnZhciB0OkxvbmdJbnQ7CmJlZ2luCiAgdDo9YTsKICBhOj1iOwogIGI6PXQ7CmVuZDsKCnByb2NlZHVyZSB3cml0ZUFycihhcnI6bGFyZ2U7IG46U21hbGxJbnQpOwpWYXIgaTpzbWFsbGludDsKYmVnaW4KICBmb3IgaTo9MCB0byBuLTEgZG8gd3JpdGUoYXJyW2ldLCAnICcpOwogIFdyaXRlbG47CmVuZDsKCnByb2NlZHVyZSBidWJibGVTb3J0KFZhciBhcnI6bGFyZ2U7IG46c21hbGxp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