#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const int N = 50;
int n;
ll m,a[N],b[N],ans;
vector<ll>S1,S2;
void Fill(vector<ll>&S,int ind,int len,ll sum){
if(ind==len+1){
S.push_back(sum);
return;
}
Fill(S,ind+1,len,sum);
if(sum+b[ind]<=m)Fill(S,ind+1,len,sum+b[ind]);
}
void Gen(vector<ll>&S,int len){
Fill(S,1,len,0);
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(n==1){
if(a[1]<=m)cout<<2;
else cout<<1;
return 0;
}
int len=n/2;
for(int i=1;i<=n/2;i++)b[i]=a[i];
Fill(S1,1,len,0);
for(int i=n/2+1;i<=n;i++)b[i-n/2]=a[i];
Fill(S2,1,n-len,0);
sort(S1.begin(),S1.end());
sort(S2.begin(),S2.end());
reverse(S2.begin(),S2.end());
int prev=0;
for(auto e:S2){
ll val=m-e;
int l=prev;
int r=(int)S1.size()-1;
int sol=0;
while(l<=r){
int mid=(l+r)>>1;
if(S1[mid]<=val){
sol=mid;
l=mid+1;
}else{
r=mid-1;
}
}
prev=sol;
ans+=1LL*(sol+1);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
3 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
720 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
2 ms |
720 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
2264 KB |
Output is correct |
2 |
Correct |
64 ms |
5712 KB |
Output is correct |
3 |
Correct |
282 ms |
21140 KB |
Output is correct |
4 |
Correct |
72 ms |
21140 KB |
Output is correct |
5 |
Correct |
13 ms |
21140 KB |
Output is correct |
6 |
Correct |
8 ms |
21140 KB |
Output is correct |
7 |
Correct |
2 ms |
21140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
21140 KB |
Output is correct |
2 |
Correct |
25 ms |
21140 KB |
Output is correct |
3 |
Correct |
111 ms |
21140 KB |
Output is correct |
4 |
Correct |
3 ms |
21140 KB |
Output is correct |
5 |
Correct |
6 ms |
21140 KB |
Output is correct |
6 |
Correct |
20 ms |
21140 KB |
Output is correct |
7 |
Correct |
2 ms |
21140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
21140 KB |
Output is correct |
2 |
Correct |
119 ms |
21140 KB |
Output is correct |
3 |
Correct |
102 ms |
21140 KB |
Output is correct |
4 |
Correct |
2 ms |
21140 KB |
Output is correct |
5 |
Correct |
55 ms |
21140 KB |
Output is correct |
6 |
Correct |
209 ms |
21140 KB |
Output is correct |
7 |
Correct |
2 ms |
21140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
21140 KB |
Output is correct |
2 |
Correct |
23 ms |
21140 KB |
Output is correct |
3 |
Correct |
9 ms |
21140 KB |
Output is correct |
4 |
Correct |
2 ms |
21140 KB |
Output is correct |
5 |
Correct |
7 ms |
21140 KB |
Output is correct |
6 |
Correct |
177 ms |
21140 KB |
Output is correct |
7 |
Correct |
3 ms |
21140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
21140 KB |
Output is correct |
2 |
Correct |
80 ms |
21140 KB |
Output is correct |
3 |
Correct |
9 ms |
21140 KB |
Output is correct |
4 |
Correct |
9 ms |
21140 KB |
Output is correct |
5 |
Correct |
72 ms |
21140 KB |
Output is correct |
6 |
Correct |
22 ms |
21140 KB |
Output is correct |
7 |
Correct |
2 ms |
21140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
21140 KB |
Output is correct |
2 |
Correct |
26 ms |
21140 KB |
Output is correct |
3 |
Correct |
11 ms |
21140 KB |
Output is correct |
4 |
Correct |
282 ms |
21140 KB |
Output is correct |
5 |
Correct |
93 ms |
21140 KB |
Output is correct |
6 |
Correct |
17 ms |
21140 KB |
Output is correct |
7 |
Correct |
2 ms |
21140 KB |
Output is correct |