Topcoder SRM 687 (Div 2) 250.Quorum

Source: Internet
Author: User

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)
{5,2,3}
1
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)
{1,1,1,1,1}
5
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)
{50,2,9,49,38}
3
returns:49
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.