This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll m;
vector<ll> a;
void f ( vector<ll> &x, vector<ll> &v )
{
int m = x.size();
for ( int i=0; i < (1<<m); i++ )
{
ll sum = 0;
for ( int j=0; j<m; j++ )
if ( (i>>j) & 1 )
sum += x[j];
v.push_back( sum );
}
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n);
for ( auto& el : a )
cin >> el;
vector<ll> x, y;
{
int m = n/2;
for ( int i=0; i<m; i++ )
x.push_back( a[i] );
for ( int i=m; i<n; i++ )
y.push_back( a[i] );
}
vector<ll> p, q;
f( x, p );
f( y, q );
sort( p.begin(), p.end() );
sort( q.begin(), q.end() );
ll ans = 0;
for ( auto& el : q )
{
ll w = m - el;
int l = -1, r = int(p.size())-1;
while ( l < r )
{
int mid = ( l + r + 1 ) / 2;
if ( p[mid] <= w )
l = mid;
else
r = mid-1;
}
ans += l+1;
}
cout << ans << '\n';
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... |