Problem Statement |
|
In one organization they has n different committees. The organization has a very large number of employees. Each employee is a member of each committee. Each of the committee has a quorum:the smallest number of members and that there is present to is a official meeting. You is given a vector <int> arr with n elements. Each element of arr is the quorum of one Committee. You is also given an int K. Yesterday, K different committees had an official meeting, all at the same time. Obviously, each person attended at the most one of the those meetings. Compute and return the smallest possible number of people who attended a meeting yesterday. |
Definition |
|
Class: |
Quorum |
Method: |
Count |
Parameters: |
Vector <int>, int |
Returns: |
Int |
Method Signature: |
int count (vector <int> arr, int k) |
(Be sure your method was public) |
|
Limits |
|
Time limit (s): |
2.000 |
Memory Limit (MB): |
256 |
Stack Limit (MB): |
256 |
|
Notes |
- |
The value of n is not given explicitly. Instead, you can determine it as the number of elements in arr. |
Constraints |
- |
arr would contain between 1 and elements, inclusive. |
- |
Each element of arr would be between 1 and 50. |
- |
k 'll be between 1 and the number of elements of arr, inclusive. |
Examples |
0) |
|
|
|
Returns:2 |
There is three committees. The First Committee requires 5 members to start a meeting, the second requires 2, and the third requires 3 members. As K=1, there is one meeting yesterday. The smallest possible solution is the It's a meeting of the Second Committee and that exactly 2 employees attended that Meeting. |
|
|
1) |
|
|
|
Returns:5 |
All five committees had a meeting yesterday. We need at least one person per meeting. No person can attend more than one meeting. Hence, there must has been at least 5 different people. |
|
|
2) |
|
|
|
3) |
|
|
{20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1} |
14 |
|
returns:105 |
|
|
This problem statement are 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 p Rohibited. (c) 2003, TopCoder, Inc. All rights reserved.
My Solution
I'll 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 <algori Thm>using namespace Std;class Quorum {public:int count (vector <int> arr, int k) {sort (Arr.begin (), Arr.end ()); in T-ans = 0;for (int i = 0; i < K; i++) ans + = arr[i]; return ans;}; </span>
Thank you!
Topcoder SRM 687 (Div 2) 250.Quorum