Educational Codeforces Round 3 A
2 seconds
256 megabytes
standard input
standard output
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to 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) — the number of USB flash drives.
The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file.
Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
3
5
2
1
3
2
3
6
2
3
2
3
2
5
5
10
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.
贪心,这个没什么好说的,拿大的放进去就好
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int t;
int n,m;
int a[1000000];
int main()
{
int sum=0;
int num=1;
cin>>n>>m;
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(i=n-1;i>=0;i--)
{
sum+=a[i];
if(sum>=m)
{
break;
}
}
cout<<n-i<<endl;
return 0;
}
Educational Codeforces Round 3 A的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- warning: control reaches end of non-void function 和 warning: implicit declaration of function 'rsgClearColor' is invalid in C99
用gcc编译一个程序的时候出现这样的警告: warning: control reaches end of non-void function 它的意思是:控制到达非void函数的结尾.就是说你的一些 ...
- 关于android写入SD卡数据的学习代码
String path = "data/data/com.example.qqlogin/login.txt"; FileOutputStream fos = new FileOu ...
- C# 把一个文件夹下所有文件删除
public static void DelectDir(string srcPath){ try { DirectoryInfo dir = new DirectoryInfo(srcPath); ...
- c语言输入数据
比如要求输入一行数据(注意:没有给出输入多少个),并且以空格隔开那么就可以如下进行判断 '; ],temp,i=; while(c!='\n') { scanf("%d%c",&a ...
- SDUT 2142 数据结构实验之图论二:基于邻接表的广度优先搜索遍历
数据结构实验之图论二:基于邻接表的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Descript ...
- css中设置div水平居中,margin:0px auto没用的情况
在CSS中加了margin:0px auto;却没有效果,不能实现居中的问题!margin:0px auto;意思就是:上下边界为0,左右根据宽度自适应!就是水平居中的意思.无效的原因是,当你没有设置 ...
- WordCount编码和测试
WordCount编码和测试 项目地址:https://github.com/handsomesnail/WordCount PSP表格 PSP2.1 PSP阶段 预估耗时(分钟) 实际耗时(分钟) ...
- python开发[第二篇]------str的7个必须掌握的方法以及五个常用方法
在Python中 基本数据类型有 str int boolean list dict tuple等 其中str的相关方法有30多个 但是常用的就以下7个 join # split # find # ...
- TestNG入门
在Eclipse中安装TestNG 打开Eclipse Help ->Install New Software , 然后Add "http://beust.com/ecli ...
- Bugly集成指南
官网: https://bugly.qq.com/v2/,用QQ扫码登录即可 1.创建应用,获取APPID 2.自动集成 2.1 在Module的build.gradle文件中添加依赖和属性配置: d ...