Submission #1248931

#TimeUsernameProblemLanguageResultExecution timeMemory
1248931JovicaIce Hockey World Championship (CEOI15_bobek)C++20
100 / 100
293 ms20892 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
int n;
ll m;
vector<ll> v;
vector<ll> op1,op2;

void f1(int p,ll z)
{
    if (p == n/2){
        op1.push_back(z);
        return;
    }
    f1(p+1,z);
    f1(p+1,z+v[p]);
}

void f2(int p,ll z)
{
    if (p == n){
        op2.push_back(z);
        return;
    }
    f2(p+1,z);
    f2(p+1,z+v[p]);
}

int main()
{
    cin>>n>>m;v.resize(n);

    for (int i=0;i<n;i++) cin>>v[i];

    if (n == 1){
        if (m >= v[0]) cout<<2;
        else cout<<1;
        return 0;
    }

    f1(0,0);
    f2(n/2,0);

    sort(op2.begin(),op2.end());

    ll odg = 0;
    for (auto x: op1)
    {
        ll p = upper_bound(op2.begin(),op2.end(),m-x) - op2.begin();
        odg += p;
        //cout<<"za "<<x<<" dodava "<<p<<endl;
    }

    cout<<odg<<endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...