Advertisement
K1R1LL

Apples

Nov 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. //Selection of apples for max sum (below you see counting sort)
  2. #include<iostream>
  3. #include<vector>
  4. #include<map>
  5. #include<algorithm>
  6. #include<clocale>
  7. #include<cmath>
  8.  
  9. using namespace std;
  10.  
  11. int a[11];
  12.  
  13. int main()
  14. {
  15.     int n , k;
  16.     cin >> n >> k;
  17.     int d;
  18.     for(int i = 0; i < n; i++)
  19.     {
  20.         cin >> d;
  21.         a[d]++;
  22.     }
  23.     int i = 1;
  24.     for(i = 1; i <= 10; i++)
  25.     {
  26.         if(a[i] >= k)
  27.         {
  28.             a[i]-=k;
  29.             break;
  30.         }
  31.         else
  32.             k -= a[i];
  33.     }
  34.     int sum = 0;
  35.     for(i; i <= 10; i++)
  36.         sum += a[i] * i;
  37.     cout << sum;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement