Advertisement
Ahmed_Negm

Untitled

Apr 9th, 2023
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.txt", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35.  
  36. ll n, m, k;
  37. vector<ll> v;
  38.  
  39.  
  40. ll DAC(){
  41.     vector<vector<ll>> left(41), right(41);
  42.     int mid = n/2;
  43.     vector<ll> l(v.begin(), v.begin()+mid), r(v.begin()+mid, v.end());
  44.     for(int i=0;i<(1<<mid);i++){
  45.         ll sum = 0, cnt = 0;
  46.         for(int j=0;j<mid;j++){
  47.             if(i&(1<<j)){
  48.                 sum += l[j];
  49.                 cnt++;
  50.             }
  51.         }
  52.         if(cnt<=m and sum<=k)left[cnt].push_back(sum);
  53.     }
  54.  
  55.     for(int i=0;i<(1<<(n-mid));i++){
  56.         ll sum = 0, cnt = 0;
  57.         for(int j=0;j<(n-mid);j++){
  58.             if(i&(1<<j)){
  59.                 sum += r[j];
  60.                 cnt++;
  61.             }
  62.         }
  63.         if(cnt<=m and sum<=k)right[cnt].push_back(sum);
  64.     }
  65.  
  66.     for(int i=0;i<=m;i++) sort(all(right[i])), sort(all(left[i]));
  67.  
  68.     ll ans = 0;
  69.  
  70.     for(int i=0;i<=m;i++){
  71.         for(auto&sum: left[i]){
  72.             for(int j=0;j<=m-i;j++){
  73.                 ll rem = k-sum;
  74.                 auto it = upper_bound(all(right[j]), rem);
  75.                 ans += it - right[j].begin();
  76.             }
  77.         }
  78.     }
  79.  
  80.  
  81.     return ans;
  82. }
  83.  
  84.  
  85.  
  86. void solve(){
  87. cin>>n>>m>>k;
  88. v = vector<ll>(n);
  89. for(auto &i : v)cin>>i;
  90.  
  91. sort(all(v));
  92. ll ans = DAC();
  93. cout<<ans<<nl;
  94.  
  95.  
  96.  
  97.  
  98. }
  99.  
  100. int main(){
  101.     Fast_IO();
  102. int t =1;
  103. //cin>>t;
  104. while(t--){
  105. solve();
  106. }
  107. return 0;
  108. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement