#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 41;
unordered_map<ll,ll> memo[MAXN];
unordered_map<ll,ll> memo2[MAXN];
int n;
ll mm;
ll a[MAXN];
ll b[MAXN];
int n1,n2;
vector<ll> p1,p2;
void solve1(int i,ll m)
{
if(m > mm)
return;
if(i == n1)
{
p1.push_back(m);
return;
}
solve1(i + 1 , m);
solve1(i + 1 , m + a[i]);
}
void solve2(int i,ll m)
{
if(m > mm)
return ;
if(i == n2)
{
p2.push_back(m);
return;
}
solve2(i + 1 , m);
solve2(i + 1 , m + b[i]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> mm;
n1 = n / 2;
n2 = n - n / 2;
for(int i = 0 ; i < n1 ; i++)
cin >> a[i];
for(int i = 0 ; i < n2 ; i++)
cin >> b[i];
solve1(0,0);
solve2(0,0);
sort(p1.begin(),p1.end());
sort(p2.begin(),p2.end());
ll ans = 0;
for(int i = 0 ; i < n1 ; i++)
{
//++ans;
auto idx = lower_bound(p2.begin(),p2.end(),mm - p1[i]) - p2.begin();
ans+=idx+1;
}
cout << ans ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
2040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
2928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
3536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
173 ms |
12832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
2036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
233 ms |
20820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |