Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Selection of apples for max sum (below you see counting sort)
- #include<iostream>
- #include<vector>
- #include<map>
- #include<algorithm>
- #include<clocale>
- #include<cmath>
- using namespace std;
- int a[11];
- int main()
- {
- int n , k;
- cin >> n >> k;
- int d;
- for(int i = 0; i < n; i++)
- {
- cin >> d;
- a[d]++;
- }
- int i = 1;
- for(i = 1; i <= 10; i++)
- {
- if(a[i] >= k)
- {
- a[i]-=k;
- break;
- }
- else
- k -= a[i];
- }
- int sum = 0;
- for(i; i <= 10; i++)
- sum += a[i] * i;
- cout << sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement