当前位置:网站首页>CF609A USB Flash Drives
CF609A USB Flash Drives
2022-07-16 08:37:00 【༺Blog༒Hacker༻】
个人简介
大家好,我是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 firstline contains positive integer n ( 1 ≤ n ≤ 100 ) — — n ( 1≤n≤100 ) —— n(1≤n≤100)—— the number of USB flash drives.
The secondline contains positive integer m ( 1 ≤ m ≤ 1 0 5 ) — — m ( 1≤m≤10^{5}) —— m(1≤m≤105)—— the size of Sean’s file.
Each of the next n n nlines contains positive integer a i ( 1 ≤ a i ≤ 1000 ) — — a_{i} ( 1≤a_{i}≤1000 ) —— ai(1≤ai≤1000)—— 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;
}

感谢各位长期以来的支持,点赞收藏是我更新的动力,下期再见,拜拜!!!
边栏推荐
- ncnn 编译与使用 pnnx 编译与使用
- "Detective Conan" 1049 words painting collapse, the role of frequent "face changes"
- 基于多尺度残差密集块和块连接级联U-Net的真实图像去噪
- 全网优秀的开源攻防武器项目
- Power buckle ----- gemstones and stones
- ValueError: The number of FixedLocator locations (7), usually from a call to set_ticks, does not mat
- 洞悉数据库迷局,2022金仓创新产品发布会召开
- Share a super useful polling + timer manager
- Load balancing LVS cluster details
- The pits encountered using arcpy (3)
猜你喜欢
![[live registration] oceanbase in simple terms, issue 7](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[live registration] oceanbase in simple terms, issue 7

在okcc中你了解呼叫并发的含义吗?

《名侦探柯南》1049话作画大崩坏 角色频频“变脸”

Kubedm install kubernetes 1.15 best practices

Uniapp code scanning native plug-ins (Google mlkit, zxing; support scanning multiple codes at the same time)

7.13学习记录

自定义类型下(枚举、联合)C语言

okcc呼叫中心系统核心技术都有哪些

VMware 虚拟机运行卡慢的解决办法

Chengdu meetup | distributed database, a new engine for enterprises to reduce costs and increase efficiency
随机推荐
二叉树刷题(一)
Big guy said * computing talk Club | Sanxingdui fantasy trip: an experience that only cloud computing can bring
力扣------宝石与石头
How to add PTZ control to the easycvr video retrieval page?
Which is the most suitable price system for the three cloud rendering platforms (I)
ReFi夏季升温:Uniswap v3和绿色资产池在Celo上启动
Sword finger offer 46: Translate numbers into strings
Interviewer: what are the methods of redis performance optimization?
464 sword finger offer (35, 05, 58, 03)
Start with a notice to prevent phishing emails
Take Celsius as a negative textbook to teach you how to judge the quality of products and avoid investment risks
What is the composition of CPU
What is EOC
Autojs learning - Application List
Brush questions of binary tree (I)
基于多尺度残差密集块和块连接级联U-Net的真实图像去噪
Well known to do apps at home and abroad
AutoJs学习-TTS抢语音红包
Introduction of some attention mechanisms in deep learning and implementation of pytorch code
声明式事务管理例题