Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int main()
- {
- int tc,m,max_w,w[100000],sum;
- scanf("%d",&tc);
- while (tc--)
- {
- scanf("%d%d",&m,&max_w);
- for (int i=0;i<m;i++)
- scanf("%d",&w[i]);
- sort(w,w+m);
- sum=0;
- int flag=1;
- for (int i=0;i<m;i++)
- {
- sum+=w[i];
- if (sum>max_w)
- {
- printf("%d\n",i);
- flag=0;
- break;
- }
- }
- if (flag) printf("%d\n",m);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement