#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#pragma GCC optimize ("Ofast","unroll-loops")
using namespace std;
const int MOD = 1e9+7;
const int MAXN = 50;
ll ans = 0 ;
ll n, m ;
void solve(ll idx , ll sum , vector<ll> arr , vector<ll> &v )
{
if(idx==arr.size() )
{
if(sum<=m)v.push_back(sum);
return ;
}
solve(idx+1,sum,arr,v);
solve(idx+1,sum+arr[idx],arr,v);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m ;
vector<ll> a , b ;
for(ll i=1;i<=n;i++)
{
ll x;
cin >> x ;
if(i%2==0)
{
a.push_back(x);
}
else
{
b.push_back(x);
}
}
vector<ll> v1,v2;
solve(0,0,a,v1);
solve(0,0,b,v2);
sort(all(v1));
sort(all(v2));
for(auto it : v1)
{
ll l = 0 ;
ll r= v2.size()-1;
ll x = -1 ;
while (l<=r)
{
ll mid =(l+r)>>1;
if(v2[mid]+it<=m)
{
x=mid;
l=mid+1;
}
else r= mid-1;
}
if(x!=-1)ans+=(x+1);
}
cout<<ans<<endl;
return 0 ;
}
Compilation message
bobek.cpp: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>&)':
bobek.cpp:17:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(idx==arr.size() )
| ~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
2040 KB |
Output is correct |
2 |
Correct |
149 ms |
5476 KB |
Output is correct |
3 |
Correct |
610 ms |
20820 KB |
Output is correct |
4 |
Correct |
162 ms |
5484 KB |
Output is correct |
5 |
Correct |
35 ms |
1656 KB |
Output is correct |
6 |
Correct |
14 ms |
1024 KB |
Output is correct |
7 |
Correct |
18 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
3048 KB |
Output is correct |
2 |
Correct |
52 ms |
2040 KB |
Output is correct |
3 |
Correct |
300 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
39 ms |
1656 KB |
Output is correct |
7 |
Correct |
17 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
3564 KB |
Output is correct |
2 |
Correct |
207 ms |
6648 KB |
Output is correct |
3 |
Correct |
207 ms |
6624 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
159 ms |
6628 KB |
Output is correct |
6 |
Correct |
538 ms |
20820 KB |
Output is correct |
7 |
Correct |
106 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
423 ms |
12756 KB |
Output is correct |
2 |
Correct |
50 ms |
2032 KB |
Output is correct |
3 |
Correct |
14 ms |
1024 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
431 ms |
12756 KB |
Output is correct |
7 |
Correct |
18 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
2032 KB |
Output is correct |
2 |
Correct |
143 ms |
5452 KB |
Output is correct |
3 |
Correct |
15 ms |
1024 KB |
Output is correct |
4 |
Correct |
15 ms |
1024 KB |
Output is correct |
5 |
Correct |
166 ms |
6688 KB |
Output is correct |
6 |
Correct |
48 ms |
2032 KB |
Output is correct |
7 |
Correct |
298 ms |
392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
592 ms |
20820 KB |
Output is correct |
2 |
Correct |
51 ms |
2032 KB |
Output is correct |
3 |
Correct |
13 ms |
1024 KB |
Output is correct |
4 |
Correct |
593 ms |
20820 KB |
Output is correct |
5 |
Correct |
237 ms |
10556 KB |
Output is correct |
6 |
Correct |
33 ms |
1656 KB |
Output is correct |
7 |
Correct |
38 ms |
384 KB |
Output is correct |