fork download
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const smax=99;
  9. type large=array[0..99] of LongInt;
  10. var data:large; n, k, i, min, max:smallint;
  11.  
  12. procedure swap(Var a, b:LongInt);
  13. var t:LongInt;
  14. begin
  15. t:=a;
  16. a:=b;
  17. b:=t;
  18. end;
  19.  
  20. procedure writeArr(arr:large; n:SmallInt);
  21. Var i:smallint;
  22. begin
  23. for i:=0 to n-1 do write(arr[i], ' ');
  24. Writeln;
  25. end;
  26.  
  27. procedure bubbleSort(Var arr:large; n:smallint);
  28. Var i, j:smallint;
  29. begin
  30. for i:=0 to n do begin
  31. for j:=i to n do begin
  32. if arr[i]>arr[j] then swap(arr[i], arr[j]);
  33. end;
  34. end;
  35. end;
  36.  
  37. function isArithProgress(arr:large):boolean;
  38. Var i:smallint; res:boolean;
  39. begin
  40. res:=True;
  41. for i:=1 to n-1 do if (arr[i]-arr[i-1])<>(arr[i+1]-arr[i]) then res:=False;
  42. isArithProgress := res;
  43. end;
  44.  
  45. begin
  46. min:=0;
  47. max:=0;
  48. read(n);
  49. n:=n-1;
  50. for i:=0 to n do read(data[i]);
  51. read(k);
  52.  
  53. bubbleSort(data, n);
  54. for i:=0 to k-1 do begin min:=min+data[i]; max:=max+data[n-i] end;
  55. write(min, ' ', max);
  56. end.
Success #stdin #stdout 0s 5276KB
stdin
5
10 5 0 -5 -9
4
stdout
-9 10