Submission #18367459


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define nl "\n"
#define ii pair<int, int>
#define MOD 1000000007
#define inf 1 << 29
using namespace std;

const int M = 42;

void solve(){

    int n; cin >> n;

    ll t; cin >> t;

    vector < ll > a(n);

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

    int d1 = n / 2;

    int d2 = n - d1;

    vector < ll > v;

    for(int mask = 0; mask < (1 << d2); mask++){

        ll s = 0;

        for(int i = 0; i < d2; i++){

            if((1 << i) & mask) s += a[i + d1]; 
        }

        v.push_back(s);
    }

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

    ll res = 0;

    for(int mask = 0; mask < (1 << d1); mask++){

        ll s = 0;

        for(int i = 0; i < d1; i++){

            if((1 << i) & mask) s += a[i]; 
        }

        if(s > t) continue;

        int idx = upper_bound(v.begin(), v.end(), t - s) - v.begin();

        if(idx > 0) idx--;

        res = max(res, s + v[idx]);
    }

    cout << res << nl;
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);

    int t = 1;
    //cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Submission Info

Submission Time
Task F - Programming Contest
User Imtiaz_Riton
Language C++ (GCC 9.2.1)
Score 600
Code Size 1205 Byte
Status AC
Exec Time 396 ms
Memory 11500 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand_01.txt AC 8 ms 3520 KiB
random_01.txt AC 2 ms 3520 KiB
random_02.txt AC 2 ms 3428 KiB
random_03.txt AC 2 ms 3424 KiB
random_04.txt AC 2 ms 3520 KiB
random_05.txt AC 2 ms 3452 KiB
random_06.txt AC 2 ms 3536 KiB
random_07.txt AC 2 ms 3524 KiB
random_08.txt AC 3 ms 3488 KiB
random_09.txt AC 3 ms 3512 KiB
random_10.txt AC 3 ms 3420 KiB
random_11.txt AC 4 ms 3552 KiB
random_12.txt AC 8 ms 3652 KiB
random_13.txt AC 48 ms 5228 KiB
random_14.txt AC 5 ms 3448 KiB
random_15.txt AC 3 ms 3496 KiB
random_16.txt AC 3 ms 3444 KiB
random_17.txt AC 3 ms 3444 KiB
random_18.txt AC 3 ms 3512 KiB
random_19.txt AC 9 ms 3640 KiB
random_20.txt AC 49 ms 5160 KiB
random_21.txt AC 4 ms 3596 KiB
random_22.txt AC 43 ms 5080 KiB
random_23.txt AC 202 ms 11424 KiB
random_24.txt AC 197 ms 11428 KiB
random_25.txt AC 197 ms 11488 KiB
random_26.txt AC 221 ms 11492 KiB
random_27.txt AC 396 ms 11448 KiB
random_28.txt AC 154 ms 11500 KiB
random_29.txt AC 154 ms 11456 KiB
random_30.txt AC 150 ms 11460 KiB
sample_01.txt AC 2 ms 3436 KiB
sample_02.txt AC 3 ms 3524 KiB
sample_03.txt AC 3 ms 3524 KiB
sample_04.txt AC 2 ms 3528 KiB