codeforces Coder-Strike 2014 Round 1 B题解题报告

B. Network Configuration
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the i-th computer it was ai kilobits per second.

There will be k participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible.

The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least k of ncomputers had the same data transfer speed and the data transfer speed on these computers was as large as possible?

Input

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of n integers: a1, a2, ..., an (16 ≤ ai ≤ 32768); number ai denotes the maximum data transfer speed on the i-th computer.

Output

Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.

Sample test(s)
input
3 2
40 20 30
output
30
input
6 4
100 20 40 20 50 50
output
40
Note

In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.


题目大意:

        给出N个计算机,K个参赛人, 每个机器都有它们的最大流量速度. 可以进行一项操作:将当前最大流量降低至任一一个速度.

        目前要使得K个参赛人的流量速度都一样,且最大,并求出它.


解法:

         排序,输出第K个机器的最大流量速度.(看懂题意很重要).


代码:

#include <cstdio>
#include <algorithm>

using namespace std;

int n, k;
int a[110];

void init() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)  scanf("%d", &a[i]);
}

void solve() {
	sort(a+1, a+n+1);
	printf("%d", a[n-k+1]);
}

int main() {
	init();
	solve();
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值