A8818 | Sockets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
输出格式
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
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted