fork download
  1. #include <stdio.h>
  2.  
  3. void sort(int a[], int size)
  4. {
  5. int temp;
  6. for(int p=1;p<size;p++)
  7. {
  8.  
  9. for(int j=0;j<size-p;j++)
  10. {
  11. if(a[j]>a[j+1])
  12. {
  13. temp=a[j];
  14. a[j]=a[j+1];
  15. a[j+1]=temp;
  16. }
  17. }
  18. }
  19. }
  20. int main()
  21. {
  22. int cases;
  23. int n;
  24. int m;
  25. int i;
  26. int arr[20];
  27.  
  28. scanf("%d",&cases);
  29. while (cases > 0) {
  30. scanf("%d",&n);
  31. scanf("%d",&m);
  32.  
  33. if(m==0 && n==0)
  34. {
  35. printf("Yes\n");
  36. cases--;
  37. continue;
  38. }
  39.  
  40. for (int j = 0; j < n; j++) {
  41. scanf("%d",&arr[j]);
  42. }
  43.  
  44. sort(arr,n);
  45. //Arrays.sort(arr);
  46.  
  47. i = n - 1;
  48. while (i >= 0) {
  49. if (arr[i] <= m) {
  50. m = m - arr[i];
  51. //arr[i] = 10001;
  52. }
  53. if (m == 0) {
  54. printf("Yes\n");
  55. break;
  56. }
  57. i--;
  58. }
  59.  
  60. if (i == -1 ) {
  61. printf("No\n");
  62. }
  63. cases--;
  64. }
  65.  
  66. return 0;
  67. }
  68.  
  69.  
Success #stdin #stdout 0s 2688KB
stdin
1
5 10
2 2 3 4 5
stdout
No