abc056d <todo>

发布时间 2023-06-21 15:50:59作者: O2iginal

https://atcoder.jp/contests/abc056/tasks/arc070_b

// https://atcoder.jp/contests/abc056/tasks/arc070_b
// 查到多种做法 二分 / dp ...
// 参考 https://blog.csdn.net/sdz20172133/article/details/90739645
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 5e3 + 10;
int a[N];

void solv()
{
    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    int pos = lower_bound(a + 1, a + 1 + n, k) - a - 1;
    int ans = pos;
    for (int i = 1; i <= pos; i++)
    {
        int s = 0;
        for (int j = pos; j; j--)
        {
            if (i == j || s >= k - a[j]) continue;
            s += a[j];
            if (s >= k - a[i])
            {
                ans --;
                break;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solv();
    }
    return 0;
}