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 <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;
struct solver
{
int n, m;
vector<int> vals;
vector<int> possh1;
vector<int> possh2;
vector<int> gethalf(int l, int r)
{
vector<int> res = {0};
for (int i = l; i < r; i++)
{
int cs = res.size();
for (int j = 0; j < cs; j++)
{
res.push_back(res[j] + vals[i]);
}
}
return res;
}
int solve()
{
possh1 = gethalf(0, n / 2);
possh2 = gethalf(n / 2, n);
sort(possh1.begin(), possh1.end());
sort(possh2.begin(), possh2.end());
int res = 0;
int rp = possh2.size();
for (int lp = 0; lp < (int)possh1.size(); lp++)
{
while (rp > 0 && possh2[rp - 1] + possh1[lp] > m) rp--;
res += rp;
}
return res;
}
};
signed main()
{
int n, m;
solver s;
cin >> n >> m;
s.n = n; s.m = m;
s.vals.resize(n);
for (int i = 0; i < n; i++) cin >> s.vals[i];
cout << s.solve() << "\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... |