Topcoder SRM 687 (Div 2) 250.Quorum __ sort
2016-04-15 01:30
489 查看
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) | ||||||||||||
|
(c)2003, TopCoder, Inc. All rights reserved.
My Solution
the smallest number of members // this "number" is "人数" in Chinese not "序号或者编号".
sort, then get the sum of top k smallest;
// 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; } };
Thank you!
------ from ProLights
相关文章推荐
- Linux入门学习笔记
- 从西直门立交桥谈IT架构与重构
- 23_System_arraycopy的使用
- Shell - 14
- Linux makefile 教程 非常详细,且易懂
- Linux学习进阶路线图
- MVC5 网站开发之七 用户功能 2 用户添加和浏览
- Linux下配置用msmtp和mutt发邮件
- uboot下用SecureCRT脚本实现一键烧写linux
- 执行多个命令的方法和script 监控 操作记录
- linux用shell发邮件
- CentOS7 下面通过keepalived 配置nginx 主从方式的双机热备
- Dubbo架构设计详解
- linux安装
- ThinkPHP框架搭建及常见问题(XAMPP安装失败、Apache/MySQL启动失败)
- 在Linux系统安装Mysql教程
- BA娱乐平台官方网站+Q【7133V5583】
- 天天彩娱乐平台官方网站+Q【7133V5583】
- A7娱乐平台官方网站+Q【7133V5583】
- 星娱娱乐平台官方网站+Q【7133V5583】