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<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 , ll arr[] , vector<ll> &v , ll k )
{
if(sum>m || idx>k)return ;
if(idx==k && sum<=m)v.push_back(sum);
solve(idx+1,sum,arr,v,k);
solve(idx+1,sum+arr[idx],arr,v,k);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m ;
ll arr[n+1];
int i = 1 ;
while(cin>>arr[i])
{
i++;
if(i==n/2)break;
}
vector<ll> v1,v2;
solve(1,0,arr,v1,i);
i = 1 ;
while(cin>>arr[i])
{
i++;
}
solve(1,0,arr,v2,i);
sort(all(v1));
sort(all(v2));
i = 0 ;ll j = 0 ;
while(i<v1.size()&&j<v2.size())
{
if(v1[i]+v2[j]>m)break;
while(v1[i]+v2[j]<=m)j++;
ans+=j+1;
i++;
}
for(int i = 0 ;i < v2.size();i++)
{
ans+=(v2[i]<=m);
}
for(int i = 0 ;i < v1.size();i++)
{
ans+=(v1[i]<=m);
}
cout<<(ans-1)/2<<endl;
return 0 ;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:45:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<v1.size()&&j<v2.size())
~^~~~~~~~~~
bobek.cpp:45:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<v1.size()&&j<v2.size())
~^~~~~~~~~~
bobek.cpp:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ;i < v2.size();i++)
~~^~~~~~~~~~~
bobek.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ;i < v1.size();i++)
~~^~~~~~~~~~~
# | 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... |