标签:
Problem Statement |
|||||||||||||
In one organization they have n different committees. The organization has a very large number of employees. Each employee is a member of each committee. Each committee has a quorum: the smallest number of members that have to be present to have an official meeting. You are given a vector <int> arr with n elements. Each element of arr is the quorum of one committee. You are also given an int k. Yesterday, k different committees had an official meeting, all at the same time. Obviously, each person attended at most one of those meetings. Compute and return the smallest possible number of people who attended a meeting yesterday. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Notes |
|||||||||||||
- | The value of n is not given explicitly. Instead, you can determine it as the number of elements in arr. | ||||||||||||
Constraints |
|||||||||||||
- | arr will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of arr will be between 1 and 50. | ||||||||||||
- | k will be between 1 and the number of elements of arr, inclusive. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
My Solution
I will add the explanation tomorrow
paste my code first ?
<span style="font-size:14px;">// BEGIN CUT HERE // END CUT HERE #line 5 "Quorum.cpp" #include <string> #include <vector> #include <algorithm> using namespace std; class Quorum { public: int count(vector <int> arr, int k) { sort(arr.begin(), arr.end()); int ans = 0; for(int i = 0; i < k; i++) ans += arr[i]; return ans; } }; </span>
Topcoder SRM 687 (Div 2) 250.Quorum
标签:
原文地址:http://blog.csdn.net/prolightsfxjh/article/details/51158409