#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(s) s.begin(),s.end()
typedef long long int ll;
vector<ll> v1,v2,v;
vector<ll>d1,d2;
ll n,m;
void solve(int idx,ll s,int t){
if(t==1) {
if(idx==(int)v1.size()) {
if(s<=m) d1.push_back(s);
return;
}
solve(idx+1,s+v1[idx],t);
solve(idx+1,s,t);
}
else{
if(idx==(int)v2.size()) {
if(s<=m) d2.push_back(s);
return;
}
solve(idx+1,s+v2[idx],t);
solve(idx+1,s,t);
}
}
/*
ll ans=0;
void solv(int idx,ll s){
if(idx==n) {
if(s<=m) {
ans++;
}
return;
}
solv(idx+1,s+v[idx]);
solv(idx+1,s);
}
*/
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) {
ll a; cin>>a;
if(i&1) v1.push_back(a);
else v2.push_back(a);
}
solve(0,0,1);
solve(0,0,2);
ll ans=0;
//solv(0,0);
/*
cout<<"one"<<endl;
for(int v:v1) {
cout<<v<<" ";
}
cout<<endl;
cout<<"two"<<endl;
for(int v:v2) {
cout<<v<<" ";
}
cout<<endl;
*/
sort(all(d1)); sort(all(d2));
sort(all(d2));
sort(all(d1));
//cout<<"set 1"<<endl;
for(ll v:d1) {
// cout<<v<<endl;
int l=0;
int r=(int)d2.size()-1;
int an=-1;
while(l<=r) {
int mid=(l+r)/2;
if(d2[mid]+v<=m) {
an=mid;
l=mid+1;
}
else{
r=mid-1;
}
}
//cout<<"max "<<an<<endl;
if(an!=-1) ans+=(an+1);
}
cout<<ans<<endl;
/*
cout<<"set 2"<<endl;
for(int v:d2) {
cout<<v<<endl;
// auto it=lower_bound(all(d2),m-v);
//cout<<(distance(d2.begin(),it))<<endl;
}
*/
//cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2424 KB |
Output is correct |
2 |
Correct |
76 ms |
5492 KB |
Output is correct |
3 |
Correct |
321 ms |
20948 KB |
Output is correct |
4 |
Correct |
76 ms |
5492 KB |
Output is correct |
5 |
Correct |
13 ms |
1660 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2936 KB |
Output is correct |
2 |
Correct |
28 ms |
2424 KB |
Output is correct |
3 |
Correct |
120 ms |
10608 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
8 ms |
1024 KB |
Output is correct |
6 |
Correct |
16 ms |
1660 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
4532 KB |
Output is correct |
2 |
Correct |
119 ms |
8560 KB |
Output is correct |
3 |
Correct |
120 ms |
8560 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
68 ms |
8560 KB |
Output is correct |
6 |
Correct |
245 ms |
20948 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
244 ms |
16852 KB |
Output is correct |
2 |
Correct |
27 ms |
2424 KB |
Output is correct |
3 |
Correct |
10 ms |
1024 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
7 ms |
1024 KB |
Output is correct |
6 |
Correct |
226 ms |
16856 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2424 KB |
Output is correct |
2 |
Correct |
73 ms |
5492 KB |
Output is correct |
3 |
Correct |
9 ms |
1024 KB |
Output is correct |
4 |
Correct |
9 ms |
996 KB |
Output is correct |
5 |
Correct |
75 ms |
8672 KB |
Output is correct |
6 |
Correct |
25 ms |
2424 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
309 ms |
20836 KB |
Output is correct |
2 |
Correct |
31 ms |
2424 KB |
Output is correct |
3 |
Correct |
10 ms |
1024 KB |
Output is correct |
4 |
Correct |
329 ms |
20800 KB |
Output is correct |
5 |
Correct |
94 ms |
10608 KB |
Output is correct |
6 |
Correct |
18 ms |
1660 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |