Sanath12345

Untitled

Jun 17th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. //Problem link :
  2. //CREDITS : sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  24. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  25. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  26. #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  27. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  28. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  29. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  30. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  31.  
  32. void err(istream_iterator<string> it){}
  33. template<typename T,typename... Args>
  34. void err(istream_iterator<string> it,T a,Args... args){
  35. cout<<*it<<" = "<<a<<endl;
  36. err(++it,args...);
  37. }
  38. ll *getfactorial(){
  39. int m=1e6;
  40. ll *fact=new ll[m+1];
  41. fact[0]=1;
  42. loop(i,1,m){
  43. fact[i]=(fact[i-1]*i)%mod;
  44. }
  45. // time complexity O(n)
  46. return fact;
  47. }
  48. vi *getfactors(){
  49. int n=2e5;
  50. vi *factors=new vi[n+5];
  51. loop(i,1,n){
  52. for(int j=i;j<=n;j+=i){
  53. factors[j].pb(i);
  54. }
  55. }
  56. // time complexity O(nlogn)
  57. return factors;
  58. }
  59. ll power(ll a,ll b,ll m=mod){
  60. if(b==0) return 1;
  61. ll smallans=power(a,b/2,m);
  62. ll ans=(smallans*smallans)%m;
  63. if(b%2==1){
  64. ans=(ans*a)%m;
  65. }
  66. return ans;
  67. // time complexity O(logb)
  68. }
  69. bool *isprime(){
  70. int m=1e6;
  71. bool *p=new bool[m];
  72. loop(i,0,m) p[i]=true;
  73. p[0]=false;
  74. p[1]=false;
  75. loop(i,2,sqrt(m)){
  76. for(int j=2*i;j<=m;j+=i){
  77. p[j]=false;
  78. }
  79. }
  80. // time complexity O(nloglogn)
  81. return p;
  82. }
  83. ll nCr(ll n,ll r,int m=mod){
  84. if(n<r) return 0;
  85. ll dp[2][r+5];
  86. memset(dp,0,sizeof(dp));
  87. int i=1;
  88. loop(k,0,1) dp[k][0]=1;
  89. loop(k,1,n){
  90. loop(j,1,r){
  91. dp[i][j]=dp[i^1][j]+dp[i^1][j-1];
  92. }
  93. i=i^1;
  94. }
  95. // time complexity O(n*r) ,in worst case O(n^2)
  96. return dp[i^1][r];
  97. }
  98.  
  99. //==================START==================
  100.  
  101. int main(){
  102. boost
  103. int t;
  104. cin>>t;
  105. while(t--){
  106. ll n,w;
  107. cin>>n>>w;
  108. ll we[n];
  109. loop(i,0,n-1) cin>>we[i];
  110. sort(we,we+n,greater<int>());
  111. // loop(i,0,n-1){
  112. // cout<<we[i]<<" ";
  113. // }
  114. // cout<<endl;
  115. multiset<int> S;
  116. loop(i,0,n-1) S.insert(w);
  117. loop(i,0,n-1){
  118. set<int>::iterator it=lower_bound(S.begin(),S.end(),we[i]);
  119. S.insert(*it-we[i]);
  120. S.erase(it);
  121. }
  122. set<int>::iterator it=lower_bound(S.begin(),S.end(),w);
  123. int ans=distance(S.begin(),it);
  124. cout<<ans<<endl;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment