2 条题解

  • 0
    @ 2025-11-28 0:26:20
    #include <bits/stdc++.h>
    #define int long long // 仅在需要大整数时使用,memset 数组为 0x3f 时去掉
    #define INF 0x3f3f3f3f
    #define PII pair<int, int>
    #define ULL unsigned long long
    #define PIII tuple<int, int, int>
    #define all(v) v.begin(), v.end()
    #define debug(a) cout << #a << " = " << a << endl;
    using namespace std;
    constexpr int N = 1 * 1e6 + 10, M = 5 * 1e3 + 10;
    
    
    void solve() {
        int n, m;
        cin >> n >> m;
        auto arr = vector<int>(n);
        auto dp = vector<int>(m);
        for (auto &x : arr) cin >> x;
        for (int i = 0; i < n; i ++) {
            for (int j = m; j >= arr[i]; j --) {
                dp[j] = max(dp[j], dp[j - arr[i]] + 1);
            }
        }
        int ans = 0;
        for (auto x : dp) ans = max(ans, x);
        cout << ans;
    }
    
    signed main() {
        ios::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
        int _ = 1;
        // cin >> _;
        while (_--) {
            solve();
        }
        return 0;
    }
    
    /**
     *    author: Nijika_jia
     *    description: C++17 Algorithm Template for Competitive Programming
     */
    
    

    信息

    ID
    5630
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    117
    已通过
    33
    上传者