CF257A.Sockets
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has a__i sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
瓦西娅有许多需要用电的设备。他有 n 个电源排插(供电线路滤波器)用于连接这些设备,其中第 i 个电源排插有 ai 个插孔。
瓦西娅总共有 m 个设备,以及房间内原有的 k 个电源插座。他可以直接将设备或电源排插插入这 k 个插座中。当然,他也可以将一个电源排插插入另一个电源排插。当一个设备(或一个电源排插)直接插入这 k 个原始插座中的任意一个,或者插入了一个本身已通电的电源排插时,该设备(或电源排插)即被视为已接入电力。
问:瓦西娅至少需要从给定的 n 个电源排插中选用多少个,才能使他全部 m 个设备都通电?注意:每个设备和每个电源排插在插入时均占用一个插孔;且每个插孔只能插入一个设备或一个电源排插。
输入格式
The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 50) — number a__i stands for the number of sockets on the i-th supply-line filter.
第一行包含三个整数 n、m、k(1 ≤ n, m, k ≤ 50),分别表示电源排插的数量、设备的数量以及他可以直接插入的插座数量。
第二行包含 n 个用空格分隔的整数 a1, a2, ..., an(1 ≤ ai ≤ 50),其中 ai 表示第 i 个电源排插上的插座数量。
输出格式
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
输出一个整数——即插满所有设备所需的供电线滤波器的最小数量。如果即使使用所有供电线滤波器也无法插满所有设备,则输出 -1。
输入输出样例
输入#1
3 5 3 3 1 2
输出#1
1
输入#2
4 7 2 3 3 2 4
输出#2
2
输入#3
5 5 1 1 3 1 2 1
输出#3
-1
说明/提示
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
在第一个测试用例中,他可以将第一个插线板滤波器直接接入电源。接入后,他获得 5 个可用插座(插线板滤波器自身提供 3 个插座,外加 2 个剩余的直连插座)用于插入设备。因此,仅需一个插线板滤波器即可插入 5 台设备。
第二个测试样例的一种最优方案是:将第二个插线板滤波器直接接入电源,并将第四个插线板滤波器接入第二个插线板滤波器的某个插座中。这样,他总共可获得恰好 7 个可用插座用于插入设备:1 个用于直接接入电源,2 个位于第二个插线板滤波器上,4 个位于第四个插线板滤波器上。若仅使用一个插线板滤波器,则无法插入 7 台设备。
输入解题思路,AI测评打分。不知道怎么写?