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>
#define int long long
using namespace std;
signed main()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> sums;
for (int i = 0; i < (1 << (n / 2)); i++)
{
int sum = 0;
for (int j = 0; j < n / 2; j++)
if ((1 << j) & i)
sum += a[j];
if (sum <= m)
sums.push_back(sum);
}
sort(sums.begin(),sums.end());
int sz = sums.size();
int cnt = 0;
for (int i = 0; i < (1 << (n - n / 2)); i++)
{
int sum = 0;
for (int j = n/2; j < n; j++)
if ((1 << (j-n/2)) & i)
sum += a[j];
int l = 0, r = sz-1;
while (r-l > 1)
{
int mid = (r+l)/2;
if (sums[mid] > m-sum)
r = mid;
else
l = mid;
}
if (sums[r] <= m-sum)
l = r;
if (sums[l] <= m-sum)
cnt+=l+1;
}
cout << cnt << '\n';
}
# | 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... |