fork(3) download
  1. #include <iostream>
  2. #include<vector>
  3. #include <string>
  4. #include <sstream>
  5. #include<algorithm>
  6. #include<cstdio>
  7. #include<cstdlib>
  8. typedef unsigned long long int ull;
  9.  
  10. using namespace std;
  11. ull ni();
  12. int compare (const void * a, const void * b)
  13. {
  14. return ( *(ull*)b - *(ull*)a );
  15. }
  16.  
  17.  
  18. ull ni()
  19. {
  20. int c = getchar();
  21. while (c != '-' && (c < '0' || c > '9')) c = getchar();
  22. int sg = 0;
  23. if (c == '-') {
  24. sg = 1;
  25. c = getchar();
  26. }
  27. ull ret = 0LL;
  28. while (c >= '0' && c <= '9') {
  29. ret = ret * 10 + c - '0';
  30. c = getchar();
  31. }
  32. return sg ? -ret : ret;
  33. }
  34. int main()
  35. {
  36.  
  37. int t,n,coun=0,k;
  38. ull p[10],m,sum=0;
  39. cin>>t;
  40. if(t>7777)
  41. t=7777;
  42. while(t--)
  43. { sum=0;
  44. coun=0;
  45. n=ni();
  46. if(n>7)
  47. n=7;
  48. else if(n<1)
  49. n=1;
  50. m=ni();
  51.  
  52.  
  53. for(int i=0;i<n;i++)
  54. {
  55. p[i]=ni();
  56. }
  57. sort(p,p+n);
  58. for(k=n-1;k>=0;k--)
  59. {
  60. sum=sum+p[k];coun++;
  61. if(sum>=m)
  62. {
  63. break;
  64.  
  65. }
  66. }
  67. if(m>sum)
  68. {
  69. coun=-1;
  70. }
  71. cout<<coun;
  72. }
  73.  
  74. }
Success #stdin #stdout 0s 2904KB
stdin
1
1 5
5
stdout
1