fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <bits/stdc++.h>
  6. #include <iomanip>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. //Baablrsuu
  12. int main()
  13. {
  14. int t;
  15. cin>>t;
  16. int n,b;
  17. int arr[101],sum=0;
  18. int len=0;
  19. for(int j=1; j<=t; j++)
  20. {
  21. sum=0;
  22. len=0;
  23. cin>>n>>b;
  24. for(int x=0; x<n ;x++)
  25. cin>>arr[x];
  26. sort(arr,arr+n);
  27.  
  28. for(int i=0; ;i++)
  29. {
  30. if(sum>=b)
  31. break;
  32. sum+=arr[i];
  33. len++;
  34.  
  35. }
  36.  
  37. cout<<"Case #"<<j<<": "<< len<<endl;
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 4476KB
stdin
3
4 100
20 90 40 90
4 50
30 30 10 10
3 300
999 999 999
stdout
Case #1: 3
Case #2: 3
Case #3: 1