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 ...
随机推荐
- [Python Study Notes]饼状图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]气泡散点图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- 返回键的复写onBackPressed()介绍
本篇文章是对Android中返回键的复写onBackPressed()进行了详细的分析介绍,需要的朋友参考下 在android开发中,当不满足触发条件就按返回键的时候,就要对此进行检测.尤其是当前Ac ...
- php验证是否建立数据库,否,则自动建立
<?php /* 默认建立的数据库为test,数据表为admin,管理员只需要修改DB_PWD(即本地的服务器密码)即可,用户密码采用md5加密 */ define(DB_HOST," ...
- ECMAScript 定义类、对象
使用预定义对象只是面向对象语言的能力的一部分,它真正强大之处在于能够创建自己专用的类和对象. ECMAScript 拥有很多创建对象或类的方法. 工厂方式 原始的方式 因为对象的属性可以在对象创建后动 ...
- PythonNote02_HTML标签
<!DOCTYPE> <html> <head> <meta charset = "utf-8" /> <meta name= ...
- c# ??和运算符先后的问题
; ; - not1??; Console.WriteLine(a); 输出结果为:10 问题因该是??运算符没有-的优先级高,实际这个 操作等于: ; ; - not1)??); 解决这个问题的办法 ...
- google的protocol buffers 对象的序列化 for java
前言: protobuf确实比JSON快很多倍,看下面的图就知道了. 环境: win7 x64 eclipse 4.3 protoc-2.5.0 安装包下载: https://code.google. ...
- Luogu 2827 [NOIP2016] 蚯蚓
原来真的是按题意模拟啊,还以为有高能的算法可以直接算每个$t$的值. 考虑到先切的蚯蚓一定比后切的蚯蚓长,于是可以弄三个队列分别存放原来的序列和两个切开后的序列,每次取出三个队头的最大值进行扩展. 考 ...
- thinkphp目录解析