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.
题意:有一个包 体积是v 后面有n种菜 每种菜有ni个单位体积 问最多能装下多少种菜
题目很简单 思路就不说了 贪心就完事 直接附代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=1e5+5;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int a[maxn];
int t,v;
scanf("%d%d",&t,&v);
for(int i=0;i<t;i++)
scanf("%d",&a[i]);
sort(a,a+t);
int s=0,sum=0;
while(s<=v)
{
s+=a[sum];
sum++;
}
printf("%d\n",sum-1);
}
}