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;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound
#define TASKNAME "NAME"
void init()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}
const int SZ = 1e6+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;
int n;
ll m, a[SZ];
vector<ll> s1, s2;
void recur1(int pos, ll sum)
{
if(pos == n/2+1)
{
s1.pb(sum);
return;
}
recur1(pos+1, sum);
recur1(pos+1, sum + a[pos]);
}
void recur2(int pos, ll sum)
{
if(pos == n+1)
{
s2.pb(sum);
return;
}
recur2(pos+1, sum);
recur2(pos+1, sum + a[pos]);
}
ll res = 0;
int main()
{
init();
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
recur1(1, 0);
recur2(n/2 + 1, 0);
sort(all(s1));
sort(all(s2));
for(ll x : s1)
{
ll y = m - x;
int pos = upper_bound(all(s2), y) - s2.begin();
res += max(0LL, 1LL*pos);
}
cout << res;
}
# | 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... |