Language: C++

#include <bits/stdc++.h>
using namespace std;

/* define const */

/* finish defineing const */

long n, k;
long cnt;
bool dp[5010][5010][5010] = {};
long a[5010];
vector<long> v;

void init_dp()
{
    for (int i = 0; i < 5010; i++)
    {
        dp[i][0][0] = true;
    }
}

void init_vector()
{
    v.erase(v.begin(), v.end());
}

bool do_dpp(long idx, long x)
{

    // int dp[5010][5010] = {};
    // dp[0][0] = 1;

    for (int i = 1; i <= n - 1; i++)
    {
        for (int j = 0; j <= 5000; j++)
        {
            dp[idx][i][j] |= dp[idx][i - 1][j];
            if (j - v[i - 1] >= 0)
            {
                dp[idx][i][j] |= dp[idx][i - 1][j - v[i - 1]];
            }
        }
    }

    for (long i = k - x; i < k; i++)
    {
        if (i >= 0)
        {
            if (dp[idx][n - 1][i] == 1)
            {
                return 1;
            }
        }
    }

    return 0;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    //input

    cnt = n;

    // dp用配列の初期化
    init_dp();

    sort(a, a + n, greater<long>());

    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    for (int i = 0; i < n; i++)
    {
        // vectorの初期化
        // vector<long> v;
        init_vector();

        // i番目を除いてvectorに格納
        for (int j = 0; j < n; j++)
        {
            if (i != j)
            {
                v.push_back(a[j]);
            }
        }

        for (auto itr = v.begin(); itr != v.end(); ++itr)
        {
            cout << *itr << " ";
        }
        cout << endl;

        // i番目を除いたvectorに対してdp
        if (do_dpp(i, a[i]))
        {
            --cnt;
        }
    }
    cout << cnt << endl;
}


Compiler output:
/tmp/cclcx8BR.o: in function `init_vector()':
a.cc:(.text+0x40): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x66): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x97): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cclcx8BR.o
/tmp/cclcx8BR.o: in function `do_dpp(long, long)':
a.cc:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x1c3): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cclcx8BR.o
/tmp/cclcx8BR.o: in function `main':
a.cc:(.text+0x35f): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x3b3): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x3c0): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x3e5): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x475): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cclcx8BR.o
a.cc:(.text+0x482): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status