Clarke and food

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 620    Accepted Submission(s): 361

Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a cook, was shopping for food.


Clarke has bought n
food. The volume of the ith
food is vi.
Now Clarke has a pack with volume V.
He wants to carry food as much as possible. Tell him the maxmium number he can brought with this pack.
 
Input
The first line contains an integer
T(1≤T≤10),
the number of the test cases.

For each test case:

The first line contains two integers n,V(1≤n≤105,1≤V≤109).


The second line contains n
integers, the ith
integer denotes vi(1≤vi≤109).
 
Output
For each test case, print a line with an integer which denotes the answer.
 
Sample Input
1
3 5
1 3 4
 
Sample Output
2 Hint:
We can carry 1 and 3, the total volume of them is 5.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[100100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,v;
memset(num,0,sizeof(num));
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
int i;
for(i=0;i<n;i++)
{
if(v-num[i]<0)
break;
else
v-=num[i];
}
printf("%d\n",i);
}
return 0;
}

 

最新文章

  1. Lua在单片机中的移植
  2. RxJava 备注
  3. 使用exp进行SQL报错注入
  4. CronTrigger:Corn表达式
  5. 421. Maximum XOR of Two Numbers in an Array——本质:利用trie数据结构查找
  6. leetcode 66
  7. Metadata Lock原理2
  8. 曝光卖假币的店铺和旺旺ID
  9. [Effective C++ --021]必须返回对象时,别妄想返回其reference
  10. Window_Open详解
  11. Android开发之发送邮件功能的实现(源代码分享)
  12. Solr学习(2) Solr4.2.0+IK Analyzer 2012
  13. P1041 传染病控制(dfs)
  14. 灰熊:在这6个信息流和DSP平台投放后,我总结了这些血泪经验!
  15. CMakeLists
  16. Python压缩指定文件及文件夹为zip
  17. SpringCloud使用Feign调用服务时,@FeignClient注解无法使用
  18. centos 7部署openvpn easy-rsa 3.0部署方法
  19. Java -- POI -- 随笔汇总
  20. mysql 压缩版安装

热门文章

  1. AIX查看某个端口被哪个进程占用
  2. LeetCode OJ 之 Number of Digit One (数字1的个数)
  3. jquery时间格式化插件
  4. Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
  5. java基础——static keyword小节
  6. 【linux】——centos 分辨率配置
  7. xBIM 基础04 日志操作
  8. BZOJ 3626 离线+树链剖分+线段树
  9. MetaSploit攻击实例讲解------社会工程学set攻击(kali linux 2016.2(rolling))(详细)
  10. FCC高级编程篇之Symmetric Difference