CF609A USB Flash Drives

📋 个人简介

💖大家好,我是2022年3月份新人榜排名第三的 ༺Blog༒Hacker༻
🎉支持我:点赞👍+收藏⭐️+留言📝
💬格言:༺永做优质༒programmer༻
📣 系列专栏:CF & UVA🍁
📝 个人主页:༺Blog༒Hacker༻❄️

注(具体请见CF665B Shopping):

⚜️我的更新时间会有所改变,每月2-5篇,感谢各位长期以来的支持!
在这里插入图片描述

📣CF609A USB Flash Drives

💠题目描述
🔆Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a 1 , a 2 , . . . , a n a_{1},a_{2},...,a_{n} a1,a2,...,an megabytes. The file size is equal to m m m megabytes.
Find the minimum number of USB flash drives needed to write Sean’s file, if he can split the file between drives.

💠输入格式
🔆The first line contains positive integer n ( 1 ≤ n ≤ 100 ) —— n ( 1≤n≤100 ) —— n(1n100)—— the number of USB flash drives.
🔆The second line contains positive integer m ( 1 ≤ m ≤ 1 0 5 ) —— m ( 1≤m≤10^{5}) —— m(1m105)—— the size of Sean’s file.
🔆Each of the next n n n lines contains positive integer a i ( 1 ≤ a i ≤ 1000 ) —— a_{i} ( 1≤a_{i}≤1000 ) —— ai(1ai1000)—— the sizes of USB flash drives in megabytes.
♻️ It is guaranteed that the answer exists, i . e . i. e. i.e. the sum of all a i a_{i} ai is not less than m m m .

💠输出格式
🔆Print the minimum number of USB flash drives to write Sean’s file, if he can split the file between drives.

在这里插入图片描述
💠输入输出样例

➰输入 #1
3
5
2
1
3
➰输出 #1
2
➰输入 #2
3
6
2
3
2
➰输出 #2
3
➰输入 #3
2
5
5
10
➰输出 #3
1

💠说明/提示
♻️In the first example Sean needs only two USB flash drives — the first and the third.

♻️In the second example Sean needs all three USB flash drives.

♻️In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.

思路

💠很简单的贪心➕模拟➕排序

💯CODE

#include<bits/stdc++.h>
#define ll long long
#define MAXN 1005
using namespace std;
ll n,m,a[MAXN],ans;
bool cmp(int x,int y)
{
    return x>y;
}
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		sort(a+1,a+1+n,cmp);
	}
	for(int i=1;i<=n;++i)
	{
		m-=a[i];
		ans++;
		if(m<=0)
		  break;
	}
	cout<<ans<<endl;
	return 0;
}

在这里插入图片描述

🔮感谢各位长期以来的支持,点赞收藏是我更新的动力,下期再见,拜拜!!!

在这里插入图片描述

  • 12
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

༺Blog༒Hacker༻

您的鼓励将是我更新最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值