fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. int n,m;
  7. int a[1005];
  8. int b[1005];
  9. cin>>n>>m;
  10.  
  11. for(int i=0;i<m;i++){
  12. cin>>a[i];
  13. b[i]=a[i];
  14. }
  15.  
  16.  
  17.  
  18. int ma=0,mi=0;
  19.  
  20. int ba = n;
  21.  
  22.  
  23.  
  24. while(ba!=0){
  25. int c = *max_element(a,a+m);
  26. int d = distance(a,max_element(a,a+m));
  27.  
  28. ma = ma + c;
  29.  
  30. a[d]= c-1;
  31.  
  32. ba--;
  33.  
  34. }
  35.  
  36.  
  37. ba = n;
  38.  
  39. while(ba!=0){
  40.  
  41. int c = *min_element(b,b+m);
  42. int d = distance(b,min_element(b,b+m));
  43.  
  44. mi = mi + c;
  45.  
  46. int f = c-1;
  47.  
  48. if(f==0) f = INT_MAX;
  49.  
  50. b[d]= f;
  51.  
  52. ba--;
  53.  
  54. }
  55.  
  56. cout<<ma<<" "<<mi<<"\n";
  57.  
  58. return 0;
  59.  
  60.  
  61.  
  62.  
  63. }
Success #stdin #stdout 0s 3472KB
stdin
510 132
50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62
Output
stdout
50279 5479