/*
_____ _ ____ _
|_ _| |__ ___/ ___| ___ _ __ | |_ _ __ ___
| | | '_ \ / _ \___ \ / _ \ '_ \| __| '__/ _ \
| | | | | | __/___) | __/ | | | |_| | | (_) |
|_| |_| |_|\___|____/ \___|_| |_|\__|_| \___/
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;
#define ll long long
ll mod = 1e9+7;
ll binpow(ll a, ll b)
{
ll res = 1;
while (b>0)
{
if (b&1)
res = (res*a)%mod;
a = (a*a)%mod;
b>>=1;
}
return res;
}
ll gcd(ll x, ll y)
{
if (y==0)
return x;
return gcd(y, x%y);
}
void solve()
{
ll n,k;
cin>>n>>k;
vector<ll>v(n);
for (int i=0 ; i<n ; i++)
cin>>v[i];
vector<ll>a,b;
for (int m=0 ; m<(1<<(n/2)) ; m++)
{
ll sum=0;
for (int i=0 ; i<(n/2) ; i++)
{
if (m&(1<<i))
sum += v[i];
}
if (sum<=k)
a.push_back(sum);
}
for (int m=0 ; m<(1<<((n+1)/2)) ; m++)
{
ll sum=0;
for (int i=n/2 ; i<n ; i++)
{
if (m&(1<<(i-n/2)))
sum += v[i];
}
if (sum<=k)
b.push_back(sum);
}
ll res=0;
sort(b.begin(), b.end());
for (auto i:a)
res += upper_bound(b.begin(), b.end(), k-i)-b.begin();
cout<<res<<endl;
}
int main()
{
// freopen ("input.txt","r",stdout);
// freopen ("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll tt = 1;
// cin>>tt;
while (tt--)
{
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |