fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. long long n,x,s=0,f=0,k=0;
  10. scanf("%lld %lld ",&n,&x);
  11. vector<long long>arr(n);
  12. for(int i=0; i<n; i++)
  13. scanf("%lld",&arr[i]);
  14. sort(arr.begin(),arr.end());
  15. /*for(int i=0; i<n; i++)
  16. printf("%lld ",arr[i]);*/
  17. while(x>=0)
  18. {
  19. if(x>=arr[k])
  20. {
  21. x-=arr[k];
  22. //printf("X is %lld\n",x);
  23. s++;
  24. k++;
  25. }
  26. else
  27. {
  28. if(arr[k]%2==0 && x<(arr[k]/2))
  29. f++;
  30. else if(x<=arr[k]/2)
  31. f++;
  32. f+=(n-1-k);
  33. //printf("N is %lld and K is %lld\n",n,k);
  34. x=-1;
  35. }
  36. }
  37. printf("%lld %lld\n",f,s);
  38. return 0;
  39. }
Success #stdin #stdout 0s 3436KB
stdin
5 7
1 3 5 7 9
stdout
2 2